Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Save New Duplicate & Edit Just Text Twitter
- # Defining Morse Code Key
- stop = False
- morseOut=' '
- morseKey = (('a','.-'),('b','-...'),('c','-.-.'),('d','-..'),('e','.'),
- ('f','..-.'),('g','--.'),('h','....'),('i','..'),('j','.---'),
- ('k','-.-'),('l','.-..'),('m','--'),('o','---'),('p','.--.'),
- ('q','--.-'),('r','.-.'),('s','...'),('t','-'),('u','..-'),
- ('v','...-'),('w','.--'),('x','-..-'),('y','-.--'),('z','--..'))
- # This is where the program will greet the user
- print('Welcome!')
- print('This program was designed to translate English to Morse Code, and Morse Code to English.')
- # This is where the program prompts the user, asking if they want Morse Code or English translated
- while stop == False:
- which = input (' Would you like to translate from Morse to English (M) or English to Morse Code (E) : ')
- while which != 'm' and which != 'e':
- which = input ('Incorrect Option! Please enter either - (m) or (e) only.')
- # translatingM = (which == 'M')
- unitIn = input('Please enter a letter, word, or phrase that you would like translated : ')
- # Input Translations
- # if translatingM == True:
- if which in "Ee":
- unitIn = unitIn.lower();
- fromIndex = 0
- toIndex = 1
- else:
- unitIn = unitIn.split()
- fromIndex = 1
- toIndex = 0
- for character in unitIn:
- letterFound = False
- if which in "Ee":
- for mainIndex in morseKey:
- if character == mainIndex [fromIndex]:
- morseOut = morseOut + ' ' + mainIndex [toIndex]
- letterFound = True
- else:
- for mainIndex in morseKey:
- if character == mainIndex [fromIndex]:
- morseOut = morseOut + mainIndex [toIndex]
- letterFound = True
- print(morseOut)
- # Reset
- translationOut = ' '
- # The Program will ask the user if another is needed
- response = input ('Do you need another translation done? (y or n): ')
- while response != 'y' and response != 'n':
- response = input ('Please enter either (y) or (n): ')
- response = response.lower();
- if response == 'n' :
- print('Thank you! Have a great day!')
- stop = True
- else:
- print(' Not a real command. Please Enter either - (m) or (e) only.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement