Multi way decisions
Estimated Time: 10 minutes
In this section, we will explore writing conditional statements when there are more than two possible outcomes.
First, we'll learn the elif
keyword. It lets you add another conditional
statement to the regular if/else
statement, so that you can write code for
situations that look like this:
Next, we'll focus on combining conditional expressions with and
, or
, and
not
. These logical operators let you express more complicated conditions
that you might use in the real world,
like "age is greater than 18, or a parent has signed the permission slip".
Finally, we'll talk about nested conditions. Lots of situations have complicated flow charts, where you take some action and then check another condition as part of that action.
Nested if
statements can express almost any flowchart, but the syntax
sometimes trips people up!