python - Allowing multiple characters in morse code converter -


i'm making program takes input , coverts morse code in form of computer beeps can't figure out how make can put more 1 letter in input without getting error.

here code:

import winsound import time  morsedict = { 'a': '.-', 'b': '-...', 'c': '-.-.', 'd': '-..', 'e': '.', 'f': '..-.', 'g': '--.', 'h': '....', 'i': '..', 'j': '.---', 'k': '-.-', 'l': '.-..', 'm': '--', 'n': '-.', 'o': '---', 'p': '.--.', 'q': '--.-', 'r': '.-.', 's': '...', 't': '-', 'u': '..-', 'v': '...-', 'w': '.--', 'x': '-..-', 'y': '-.--', 'z': '--..' } while true:      inp = raw_input("message: ")     = morsedict[inp]      morsestr =      c in morsestr:         print c         if c == '-':             winsound.beep(800, 500)         elif c == '.':             winsound.beep(800, 100)         else:             time.sleep(0.4)           time.sleep(0.2) 

right takes 1 letter @ time want take phrases.

just add loop , loop through characters in input message! don't forget end loop when necessary!

in following code made such after message has been decoded, asks if send another, if type "n" quit loop!

going = true while going:      inp = raw_input("message: ")     in inp:         = morsedict[i]          morsestr =          c in morsestr:             print c             if c == '-':                 winsound.beep(800, 500)             elif c == '.':                 winsound.beep(800, 100)             else:                 time.sleep(0.4)               time.sleep(0.2)     again = raw_input("would send message? (y)/(n) ")     if again.lower() == "n":          going = false 

now still have 1 problem...you have not accounted spaces!! can still send words! if correct, space between words fixed timed silence in morse code, should add:

" ": 'x' 

this way not return error when trying find instance of space , run in else statement , add .4 seconds before next word!


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -