Professional Documents
Culture Documents
ELSE Statements
if test1:
statement(s)1
elif test2:
statement(s)2
else:
statement(s)3
Python IF...ELIF...ELSE Statements
age = 20
#simple if
if age > 18:
print("I can vote") # remember indentation
#if-else
if age > 18:
print("I can vote")
else:
print("I cannot vote")
#if-elif-else
if age > 18:
print("I can vote")
elif age == 18:
print("I just turned 18 and can vote too")
else:
print("I cannot vote")
Test syntax
== equal to
and != not equal to
or > greater than
not < less than
True >= greater than or equal
False <= less than or equal
Figure out if these are True or False and then try them out in Python:
def c2(arg):
if arg < 2:
return arg*10
else:
return arg**2
x2=c2(1)
print(x2)
x3=c2(3)
print(c3)