1age = 82member = False3if age < 13:4 price = 55elif age >= 65 or member:6 price = 67else:8 price = 109print(price)??agememberpriceprice = 5printprice = 6price = 10
Code card: the program; highlighted lines are the ones explainedMemory boxes: age, member and priceTrack: every path the program could take; the lit lane is the one takenSigns: the True or False each test producedThe token is the line Python is running. At each fork the sign shows the bool its test produced, and the token takes the one lane whose block runs; the other lanes stay white. The same nine lines run three times: age 8 takes the if lane and prints 5, age 30 takes the else lane and prints 10, and age 30 with member = True takes the elif lane and prints 6. Python checks the tests from the top, runs the block of the first one that is True, and skips every other block of that if statement; tests below the True one are not even evaluated.

if and True

  1. Lines 1 and 2 store two values: age is 8 and member is False. The program uses them to choose a ticket price. The track on the right shows every path it could take.

elif and else

and, or, not

Try it in Python

;; step 1/10 · run 1: age = 8, member = False
>>> age = 8
>>> member = False
>>> type(member)
<class 'bool'>

Python checks the tests from the top, runs the block of the first one that is True, and skips every other block of that if statement; tests below the True one are not even evaluated. An if accepts any value, not only True and False. 0, 0.0, an empty string "" and None count as false; most other values count as true.