Book
Week 2 - Section 1 - Controlling the flow v2
Week 2 - Section 1 - Controlling the flow v2
In this second section we will start to learn how to control the flow of the algorithm using the if statement
Chapter 3.3 - If inside an if = nested if?
3.3 - Nested if
Sometimes we want to check a condition inside another condition.
If we want to issue a forecast for temperature and humidity we can write the simple code below.
In order for the second condition (humidity) to be examined the first (temperature > 30) must be true.
Copy and paste the following code to Thonny. You can view the steps of execution using the Debug button.
print ("This is my weather forecast")
tempr = int(input("Please insert the Temperature in Celsius : "))
hum = int(input("Please insert the Humidity of the air : "))
if tempr > 30:
if hum > 80:
print ("It's hot and humid")
else:
print ("It's hot but not humid")
else:
print ("It's not hot")