Python loop program -


can me out morse code progam , want user input either t or m; t text , m morse code everytime run no matter if input t says enter morse code translate instead of enter text translate, id appreciate help!

while true:     print("")     input = input("my input is: ")     message=input("enter morse code translate: ")     encodedmessage = ""     if input.startswith ("m"):         word in message.split("   "):             char in word.split():                 if char in morse:                     encodedmessage+=morse[char] + " "                     print("your translation text is: ",encodedmessage)                 else:                     print("value %r not found morse."%char)                     if input.startswith ("t"):                     print("enter text translate: ")                     decodedmessage = ""                     word in hello.split():                         if char in morsecode:                             decodedmessage+=morsecode[char] + " "                             print("your translation morse is: ",decodedmessage)                         else:                             print("value %r not found character."%char) 

you had second if statement input starting t way far indented such execute if input started "m" (and fail). next, had input asking morse code outside if statements (so it'd shown, not after verified looking for). i've changed closer think wanted:

while true:     print("")     input = input("my input is: ")     if input.startswith ("m"):         message=input("enter morse code translate: ")         encodedmessage = ""         word in message.split("   "):             char in word.split():                 if char in morse:                     encodedmessage+=morse[char] + " "                 else:                     print("value %r not found morse."%char)            print("your translation text is: ",encodedmessage)     elif input.startswith ("t"):         hello = input("enter text translate: ")         decodedmessage = ""         word in hello.split():             char in word:                 if char in morsecode:                     decodedmessage+=morsecode[char] + " "                 else:                     print("value %r not found character."%char)         print("your translation morse is: ",decodedmessage) 

i've moved final print lines outside of loops wouldn't want print out encoded/decoded message @ each character, end result. added loop in case you're looking @ text loop through each character in word.