Professional Documents
Culture Documents
12 If Elsif Else
12 If Elsif Else
1
Welcome Python Programming
Conditionals: if-else continued
prutor.ai
2
Oct-16 Programming
Finding min of 3 numbers
Given
a,b,c
prutor.ai
TRUE FALSE
a<=b
prutor.ai
a c
prutor.ai
if a <= c:
…
else:
…
else:
if b <= c) :
…
else:
… 5
Oct-16 Programming
Elif
• A special kind of nesting is the chain of if-else-if-
else-… statements
• Can be written elegantly using if-elif-..-else
if cond1:
prutor.ai
if cond1:
s1 s1
else: elif cond2:
if cond2: s2
s2 elif cond3:
else: s3
if cond3: elif …
s3 else
else: last-block-of-stmt
…
6
Oct-16 Programming
Summary of if, if-else
7
Oct-16 Programming