Member Avatar for leegeorg07

i have a program that converts text into morse code and then outputs it using a module i found in the snippets section but whenever i try to run it, it raises the error that "utext is not iterable"
here is the code:

morse_code={
    "a":beeps.a(),
    "b":beeps.b(),
    "c":beeps.c(),
    "d":beeps.d(),
    "e":beeps.e(),
    "f":beeps.f(),
    "g":beeps.g(),
    "h":beeps.h(),
    "i":beeps.i(),
    "j":beeps.j(),
    "k":beeps.k(),
    "l":beeps.l(),
    "m":beeps.m(),
    "n":beeps.n(),
    "o":beeps.o(),
    "p":beeps.p(),
    "q":beeps.q(),
    "r":beeps.r(),
    "s":beeps.s(),
    "t":beeps.t(),
    "u":beeps.u(),
    "v":beeps.v(),
    "w":beeps.w(),
    "x":beeps.x(),
    "y":beeps.y(),
    "z":beeps.z(),
    "":""}
print"Hello, what do you want to convert?"
utext=raw_input("").lower
for letter in utext:
    morse_code[letter]

At first sight, it seems that you forget to call lower() .

Member Avatar for leegeorg07

thanks that works great, i also have a problem that i dont know the cause of, whenever i run it, it plays the entire morse code before asking the question. i have checke beeps.py and it isnt coming from that, what could it be?

Member Avatar for leegeorg07

and unfortunately it only removed the error, it wont play them after i have entered the text

I suppose that the sound for "a" is played when beeps.a() is called. Your program plays all the letters when you fill your dict. What you could do is forget about the dict and write this

for letter in utext:
    if hasattr(beeps, letter):
        getattr(beeps, letter)()

Also, when you have a traceback, put the traceback in your posts. It's very useful for helpers.

Also you should check if there is something to put between the words in the morse code.

Member Avatar for leegeorg07

oh thanks, thats brilliant! i did a bit of looking around and i think that if you were to be using it in real life you would have the spaces and would use your intelligence to figure out where the would be :( but oh well, time to have some fun with this :D

Member Avatar for leegeorg07

i decided that i would expand it by adding in numbers but i cant really use

def 1():

can i? so i was wondering what i could do, considering i am using hassattr and getattr

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.