Error with else


#1

Hi ladies and gents,

I am getting an error in my code. Can you help me out please?

Here is my code:

print "Welcome to Anna's Pig Latin Translator"

pyg = 'ay'

original = raw_input('Enter a word:')

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

print new_word

else:
    print 'empty'

The error is get is this: File "python", line 15
else:
^
SyntaxError: invalid syntax


I would like to make another comment. It would be helpful to have a python cheat list (like a list of all the codes we have learned, somewhere on the site so that we can refer back to it when we forget something)


#2

well, if you want if and else make sure the indention is correct:

if something:
   print "i am inside the if statement"
else:
   print "this is correct"

however, the moment you do this:

if something:
   print "i am inside the if statement"
print "i am outside the if statement, now you can't use else anymore"
else:
   print "this will give an error"

notice the indention, the moment you go back to same indent level as if, you can't have a else anymore. Else always have to come after a if or a else if. You will have to tweak this solution