pyg = 'ay'
2 original = raw_input ('Enter a word:')
3 if len(original) > 0 and original.isalpha():
4 word = original.lower()
5 first = word
6 new_word = word + first + pyg
7 new_word = new_word[1:len(new_word)]
8 print new_word
10 print 'empty'
it says there's a error in line two
pyg = 'ay'
The problem is actually on line 7. The python just says its on line 2 because it took the user's input on that line.
On line 7 you modify the variable you created on line 6 new_word to slice the user's input so that the first letter becomes the last. but what you did was try and modify new_word twice on the same line.
new_word = word + first + pyg new_word = new_word[1:len(new_word)]
new_word = word + first + pyg new_word = word[1:len(new_word)] + first + pyg
Who says what?
Perhaps you're using a different Python version, the above code looks like it's meant for Python 2.7, Python 3.x doesn't have a
raw_input function, it was renamed to
Sometimes an error is reported further down than where the mistake is, but not the other way around. (Exceptions are raised when Python can no longer do what's asked. That might not happen immediately when reading the mistake)
Thank you so much! I was stuck on two days by trying to solve it by myself, however, your advice was correct and it worked for me too as I had the same mistake. Thanks again!