Translates AND gives "empty" message


#1



Pyg Latin

I wanted the code to only display the error message if the word is empty or has numbers but it shows the translation as well. Is there a way I can make it restart and give the prompt asking for an input again instead?


pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    print "Original Word: " + original
else:
    print 'Invalid Input'
    

word = original.lower()
first = word[0]

new_word = word + first + pyg

new_word = new_word[1:len(new_word)]
print "Translation: " + new_word


#2

Hi @sebastianedwards,

This line and all of the code after it should only execute if original is valid ...

word = original.lower()

Therefore you should move it all into the if block, after this line ...

print "Original Word: " + original

... and see what @mtf has written below ...


#4

Of course! thank you. That seems to be the problem - i'll go back and try it out. :slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.