I have already finished this lesson, but I would like to fix a bug.
If I leave empty when the software ask me a word this error appear:
Traceback (most recent call last): File "D:/Desktop/Francesco/Python/boh.py", line 5, in <module> first = word IndexError: string index out of range
instead of "Write an english word".
I try to change the code like this
if len(word) == 0: print "Write an english word elif ....etc
but doesn't work
This is the original code.
print 'Welcome to the Pig Latin Translator!' pyg = 'ay' original = raw_input("Enter a word:") word = original.lower() first = word new_word = word[1:len(word)] + first + pyg if len(original) > 0 and original.isalpha(): print new_word elif original.isalnum(): print "No numbers allowed" else: print "Write an English word"
How can I fix this?