#!/usr/bin/python -tt # Licensed under the Apache License, Version 2.0 # http://www.apache.org/licenses/LICENSE-2.0 """A Python program to output phonetic names for each letter in an input statement. Try running this program from the command line like this: python phonetic2.py python phonetic2.py YHF That should print: Whiskey Tango Foxtrot -or- Yankee Hotel Foxtrot """ import sys import re # Define a main() function that prints the phonetic alpha. def main(): # First, define the dictionary: dict = {} dict['A'] = 'Alpha' dict['B'] = 'Bravo' dict['C'] = 'Charlie' dict['D'] = 'Delta' dict['E'] = 'Echo' dict['F'] = 'Foxtrot' dict['G'] = 'Golf' dict['H'] = 'Hotel' dict['I'] = 'India' dict['J'] = 'Juliet' dict['K'] = 'Kilo' dict['L'] = 'Lima' dict['M'] = 'Mike' dict['N'] = 'November' dict['O'] = 'Oscar' dict['P'] = 'Papa' dict['Q'] = 'Quebec' dict['R'] = 'Romeo' dict['S'] = 'Sierra' dict['T'] = 'Tango' dict['U'] = 'Uniform' dict['V'] = 'Victor' dict['W'] = 'Whiskey' dict['X'] = 'X-Ray' dict['Y'] = 'Yankee' dict['Z'] = 'Zulu' # Get the name from the command line, using 'WTF' as a fallback. if len(sys.argv) >= 2: name = str.upper(sys.argv[1]) else: name = 'WTF' #Initialize some variables to help with the translation. i = 0 final = '' #Replace each letter and print its phonetic alpha. while i < len(name): final = final + ' ' + dict[name[i]] i = i + 1 print name + " --> " + str.strip(final) # This is the standard boilerplate that calls the main() function. if __name__ == '__main__': main()