Conditionals in Python by Ctrl-Zombies
Conditionals homework in Python
Nested Conditionals Python Homework
Python Popcorn Hack
weather = "rainy"
temperature = 50
if weather == "sunny":
if temperature > 70:
print("It's a nice warm day!")
else:
print("Could be a bit chilly, wear a jacket!")
else:
if weather == "rainy":
print("☔ Don't forget your umbrella!")
else:
print("Have a great day!")
☔ Don't forget your umbrella!
Part A: Python Practice
Write a code cell that helps decide what type of transportation someone should take.
- If the weather is
"rainy"
:- If they have an umbrella -> print
"Take the bus!"
- If they don’t -> print
"Call an Uber!"
- If they have an umbrella -> print
- If the weather is
"sunny"
:- If they have a bike -> print
"Bike!"
- If they don’t -> print
"Walk!"
- If they have a bike -> print
Example Starter Code
weather = "sunny"
has_umbrella = False
has_bike = True
# Write your nested conditionals here!
weather = "sunny"
has_umbrella = False
has_bike = True
if weather == "rainy":
if has_umbrella:
print("Take the bus!")
else:
print("Call an Uber!")
else:
if has_bike:
print("Bike!")
else:
print("Walk!")
Bike!