the
elif
block must
immediately follow an
if
(or another
elif
) one. For example, this is allowed
if i<5:
print("i is less than 5")
elif i<20:
print("i is between 5 and 19")
else:
print("i greater thn 19")
This is allowed as well
if i<5:
print("i is less than 5")
print(i)
elif i<20:
print("i is between 5 and 19")
else:
print("i greater thn 19")
This is NOT allowed
if i<5:
print("i is less than 5")
print(i)
elif i<20:
print("i is between 5 and 19")
else:
print("i greater thn 19")
because, when execution reached the
print(i)
statement (note its indentation), the
if
block has already completed.