Bolt has reached a fork in the trail.
His scanner reports a danger level of
8 out of 10.
Use an if condition to decide
which route he should take.
Your Python condition will choose Bolt's route.
Longer, but protected from the danger ahead.
Shorter, but dangerous when the scanner reading is high.
The variable
danger_level
stores the scanner reading.
If the danger level is greater than
5, Bolt should take the safe path.
Otherwise, he can use the fast path.
danger_level > 5
if
and
else
If
danger_level
were
3,
which branch would run?
You used an
if/else
condition to make your program choose between
two different actions.