10/11 task, I am stuck and I do not understand why


#1

Hello there,

I am working on the 10/11 slicing exercise for the PygLatin Translator. My code is the one in the image below, and I keep getting the error shown there:

I have moved forward by taking the action print new_word out from the if statement, and locating it after the else statement, as follows:

pyg = ‘ay’

original = raw_input('Enter a word: ')

if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
new_word = word + first + pyg
new_word = new_word[1:len(new_word)]

else:
print ‘empty’

print new_word

But I do not understand why exactly I am getting an error with the first option: shouldn´t it work fine by having an action inside the if statement, before the else one?

Any comments are welcome!

Thanks!


#2

Are you sure you are not mixing tabs and spaces in your indentation white space?

Because it would be the problem, try this again but be sure to avoid spaces between indentation:

pyg = ‘ay’

original = raw_input('Enter a word: ')

if len(original) > 0 and original.isalpha():
    word = original.lower()
    first = word[0]
    new_word = word + first + pyg
    new_word = new_word[1:len(new_word)]
    print new_word
else:
    print ‘empty’

#3

:man_facepalming:

I WAS using spaces instead of tabs. I guess this is a very newbie mistake (this is my first experience with any programming whatsoever).

Thanks a lot for your answer, now it is solved and it totally makes sense!


#4

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