Learn
Control Flow
Review
Great job! We covered a ton of material in this lesson and we’ve increased the number of tools in our Python toolkit by several-fold. Let’s review what we’ve learned this lesson:
- Boolean expressions are statements that can be either
True
orFalse
- A boolean variable is a variable that is set to either
True
orFalse
. - We can create boolean expressions using relational operators:
==
: Equals!=
: Not equals>
: Greater than>=
: Greater than or equal to<
: Less than<=
: Less than or equal to
if
statements can be used to create control flow in your code.else
statements can be used to execute code when the conditions of anif
statement are not met.elif
statements can be used to build additional checks into yourif
statements
Let’s put these skills to the test!
Instructions
1.
Optional: Little Codey is an interplanetary space boxer, who is trying to win championship belts for various weight categories on other planets within the solar system.
Write a space.py program that helps him keep track of his target weight by:
- Checks which number
planet
is equal to. - It should then compute his weight on the destination planet.
Here is the table of conversion:
# | Planet | Relative Gravity |
---|---|---|
1 | Mercury | 0.38 |
2 | Venus | 0.91 |
3 | Mars | 0.38 |
4 | Jupiter | 2.34 |
5 | Saturn | 1.06 |
6 | Uranus | 0.92 |
7 | Neptune | 1.19 |