























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!
























Python for Everybody www.py4e.com
x = 5 if x < 10: print('Smaller') if x > 20: print('Bigger') print('Finis') x = 5 x < 10? print('Smaller') x > 20? print('Bigger') print('Finis') Yes No Yes No
x = 5 if x == 5 : print('Equals 5') if x > 4 : print('Greater than 4 ') if x >= 5 : print('Greater than or Equals 5') if x < 6 : print('Less than 6') if x <= 5 : print('Less than or Equals 5') if x != 6 : print('Not equal 6')
One-Way Decisions x = 5 print('Before 5 ') if x == 5 : print('Is 5 ') print('Is Still 5 ') print('Third 5 ') print('Afterwards 5') print('Before 6') if x == 6 : print('Is 6') print('Is Still 6') print('Third 6') print('Afterwards 6')
x == 5?
print('Still 5') print('Third 5')
x = 5 if x > 2 : print('Bigger than 2') print('Still bigger') print('Done with 2') for i in range(5) : print(i) if i > 2 : print('Bigger than 2') print('Done with i', i) print('All Done')
x = 5 if x > 2 : print('Bigger than 2') print('Still bigger') print('Done with 2') for i in range(5) : print(i) if i > 2 : print('Bigger than 2') print('Done with i', i) print('All Done') Think About begin/end Blocks
Two-way Decisions
x > 2 print('Bigger') no yes x = 4 print('Not bigger')
Two-way Decisions with else: x > 2 print('Bigger') no yes x = 4
x = 4 if x > 2 : print('Bigger') else : print('Smaller') print('All done') print('Not bigger')
More Conditional Structures…
if x < 2 : print('small') elif x < 10 : print('Medium') else : print('LARGE') print('All done') x < 2 print('small') yes no
x < 10 print('Medium') yes print('LARGE') no
x = 5 if x < 2 : print('small') elif x < 10 : print('Medium') else : print('LARGE') print('All done') x < 2 print('small') yes no
x < 10 print('Medium') yes print('LARGE') no
x = 20 if x < 2 : print('small') elif x < 10 : print('Medium') else : print('LARGE') print('All done' ) x < 2 print('small') yes no
x < 10 print('Medium') yes print('LARGE') no
if x < 2 : print('Below 2') elif x < 20 : print('Below 20') elif x < 10 : print('Below 10') else : print('Something else') if x < 2 : print('Below 2') elif x >= 2 : print('Two or more') else : print('Something else' )