Python programs use if commands and conditions to make decisions.
Indentation (4 spaces) is used to show what actions have to be taken.
if
Do something or nothing:
1 2 3 4 | # if temperature < 17 : print ( 'It is too cold' ) # |
if-else
Do one thing or another:
1 2 3 4 5 6 | # if speed > 60 : print ( 'That is over the national speed limit' ) else : print ( 'That is inside the national speed limit' ) # |
if-elif-else:
Do one of several things:
01 02 03 04 05 06 07 08 09 10 11 12 | # if mark > = 70 : grade = 'A' elif mark > = 60 : grade = 'B' elif mark > = 50 : grade = 'C' elif mark > = 40 : grade = "D" else : grade = "F" # |