Conditional statements.
Goal: Learn about conditional statements
in
python.
The if and else statements provide an easy way to perform tests. For instance:
if x != y:The indentation is required to isolate the if and else clauses, but the else clause is optional. Do nothing clauses can be created by using the pass statement.
print 'x is not equal to y'
else:
print 'x and y are equal'
if x != y:Multiple test cases can be implemented using the elif clause.
pass
else:
print 'x and y are equal!'
if x == 'n':Boolean expressions can be formed by using or, and, and not keywords.
print 'Answered no'
elif x == 'y':
print 'Answered yes'
else:
print 'invalid answer'
if x > y and z > x:
print 'z is the max value'
if not (x==z or y==z or x==y):
print 'There are no equal values'