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
- A boolean variable is a variable that is set to either
- We can create boolean expressions using relational operators:
!=: Not equals
>: Greater than
>=: Greater than or equal to
<: Less than
<=: Less than or equal to
ifstatements can be used to create control flow in your code.
elsestatements can be used to execute code when the conditions of an
ifstatement are not met.
elifstatements can be used to build additional checks into your
Let’s put these skills to the test!
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 Codey keep track of their target weight by:
- Checks which number
planetis equal to.
- It should then compute their weight on the destination planet.
Here is the table of conversions:
Click to see a hint!To compute their weight on the planet they are fighting on, multiply their earth weight and the relative gravity of that planet:
if planet == 1: weight = weight * 0.91 elif planet == 2: weight = weight * 0.38 elif planet == 3: weight = weight * 2.34 elif planet == 4: weight = weight * 1.06 elif planet == 5: weight = weight * 0.92 elif planet == 6: weight = weight * 1.19 print("Your weight:", weight)
Full solution code can be found here.