Hi guys i just started with Python (3.5) trying to complete an assignment on Coursera and i keep getting the above error
Age = 15
if Age >=15 :
print ("Highschool")
else if
print ("No HighSchool")
Hi guys i just started with Python (3.5) trying to complete an assignment on Coursera and i keep getting the above error
Age = 15
if Age >=15 :
print ("Highschool")
else if
print ("No HighSchool")
Python, unlike many programming languages, relies on indentation to dictate scope. In particular, it permits tabs or certain number of spaces to indicate scope. Contiguous lines with the same indentation level are all in the same scope.
Your code:
Age = 15
if Age >=15 :
print ("Highschool")
else if
print ("No HighSchool")
Has indentation that is uneven, which confuses the python interpreter. You seem to be using 4 spaces to indicate indentation, but your else if
statement (should be else:
by the way) is not at any indentation level that makes sense. You use 3 spaces before the else if
statement. You should actually be using 0 spaces, as it is operating at the same scope/level of the if
statement.
Age = 15
if Age >=15 :
print ("Highschool")
else:
print ("No HighSchool")
Read more about Python's whitespace here.
The problem is that the else
matching an if
MUST occur at exactly the same indentation level as the if
. Also, there's no need for another if
following the else
. Try
Age = 15
if Age >=15:
print ("Highschool")
else:
print ("No HighSchool")
You should find that works better· Remember the colons - they are important!