Need advice with PygLatin


#1

Hi, guys! My code is working, but i want to improve it. Now this code is "translating" the word even if it haves digits or spaces, but i want to make an error message if user enters a word with spaces or digits, and ask him to re-enter the word without spaces and digits. Then, if all is correct, code must to "translate" the word.
Sorry for bad english, i'm not native speaker : D
Thank you!
Here it is:

print 'Welcome to the Pig Latin Translator!'

original = raw_input("Enter a word:")

if len(original) > 0 and original.isalpha():
    print original
elif original.isdigit():
    print "Words are contains letters, dude!"
else:
    print "Don't use numbers or spaces, bro!"
pyg = 'ay'
word = original.lower()
first=word[0]
new_word=word[1:] + first + pyg

print new_word

#2

Hard to give any input without the code being correctly formatted. Copy it in, highlight it and press the </> button on top of the input box.


#3

Now all is OK?
Thank you for helping


#4

You want to put the code doing the translating inside the if-else statement. As you've noticed the meat of the function will always run as you've written it now.

A little general pseudo-code example on how to do user input testing without getting into more advanced functionality:

def func(arg):
    if(type(arg) is not correct_type):
        print "Error: wrong type of input"
    else:
        # Do the function

#5

I'll try this, thank you!