Branching¶
Note
Learning objectives: Explain equalities of numbers and strings. Create a conditional logic tree for branching. Modeling a program on the prior lesson, write a comparison involving if.
- The if statement does your basic branching. Here is the structure.
Pretend <bool test> is some Boolean test like “myvariable == 1”.
So, how do we make a Boolean test? We use equality and comparison statements.
The following statements evaluate as True.
>>> 1 == 1.0
True
>>> 1 >= 1.0
True
>>> 2.0 >= 1
True
>>> 2 > 1
True
>>> 'a' <= 'b'
True
>>> 'A' < 'a'
True
>>> 'squirrel'.upper() == 'SQUIRREL'
- Based on the prior lesson, write a program and…
ask the user his or her age.
Print “You are an adult!” if the user is equal to or greater than 18, but less than 25
Tell the user “You may feel like a grown-up” if he is 25 or older.
Otherwise, tell the user “You are a a real grown-up,”