HotChile HotChile - 5 months ago 12
Python Question

If statment SyntaxError: invalid syntax?

I am trying to run a simple program but I can't seem to get over this syntax error.

try:
grade = float(raw_input("Enter a score between 0.0 and 1.0:\n"))
if grade < 0 or grade > 1
print ("That is not between 0.0 or 1.0")
elif grade >= .9
print ("A")
elif grade >= .8 and grade < .9
print ("B")
elif grade >= .7 and grade < .8
print ("C")
elif grade >= .6 and grade < .7
print ("D")
else grade < .6
print ("F")

except:
print ("Enter a numeric value!")


The error I get is line 3, if grade < 0 or grade > 1: SyntaxError: invalid syntax. Help?

Answer

if, elif, and else statements (along with a few others) in Python require a colon at the end of the line. For example:

if grade < 0 or grade > 1:

Also, else is a catch-all and thus does not use a condition.

else: