



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Today ...
Logical expressions can be nested
((not (2 > 3)) or (4 < 2)) and not ((2 > 3) or False) True
If operands are not Boolean expressions, Python will convert for us
17 and 54 54
0 or 20 20
len([10, 20]) or "spam" 2
len([10, 20]) and "spam" "spam"
What is going on?
Conditional statement syntax if boolean condition: statement statement ...
Flow Charts
if x < y: # condition x = x + 1 # if statement y = y - 1 # statement after if
Condi&on
Statement
Statement
False True x^ <^ y^?
x = x + 1
y = y - 1
No Yes
If-Else statement syntax if boolean condition: statements else: statements
The flow chart
if x < y: x = x + 1 else x = x - 1 y = y - 1
Condi&on
Statement
Statement
False True x^ <^ y^?
x = x + 1
y = y - 1
No Yes
Statement x = x - 1
Simple example using elif conditional statement ...
def min3(x, y, z): if x <= y and x <= z: return x elif y <= x and y <= z: return y else: return z