I am trying to solve this CodingBat problem:
Squirrels who like to party get together and smoke cigars. Such a party is only deemed successful when the number of cigars is between 40 and 60, on a weekday. On weekends, however, there is no upper bound on number of cigars. Write a function that returns True if the party with the given values was successful.
Unfortunately, although I have used Python occasionally, I am not good enough at it to understand why my code fails with a syntax error on line 5:
def cigar_party(cigars, is_weekend):
if is_weekend:
if cigars >= 40:
return True
else if:
cigars >= 40 and cigars =< 60:
return True
else:
return False
In Python you need to use
elifinstead ofelse if.More information:
http://docs.python.org/2/tutorial/controlflow.html
Also change the following line:
To this:
The less than or equal to sign needs to be
<=and there should not be a colon between the keyword elif and the rest of the expression.