The course counts my code as working, and I don't have a problem when I put in an actual word, but when I leave the box empty, I get an error:
Traceback (most recent call last):
File "python", line 4, in
IndexError: string index out of range
I anticipated the code would print empty when I didn't put a word in because it's character count is < 0 and wouldn't be considered a letter, so it wouldn't reach the conclusion of the if-and statement. Instead, I'm getting the above syntax error. Is it because of where I placed it in the code? Any explanation will do.
original = raw_input('Enter a word:') pyg = 'ay' word = original.lower() first = word new_word = word + first + pyg new_word = new_word[1:len(new_word)] if len(original) > 0 and original.isalpha(): print new_word.lower() else: print 'empty'