Else statement


#1

I’m having an error pop up for my else statement when previously it was fine . Can someone let me know what I’m doing wrong ?

Thanks


#2

else always needs to be after an if or an elif, let me show you:

if True:
   print "i am true"
else:
   print "i am false"

however, if you move lines outside/after the if clause, you can’t have else anymore, this will throw an error:

if True:
   print "i am true"
print "this will throw an error"
print "the else is no longer after if or elif"
print "these print statements screw this up"
else:
   print "i am false"

read the text in the print statements, they are big hint

now take a second to think what you need to do. Don’t go and delete the else in a hurry


#3

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