Book
Module 2 - Section 1 - Controlling the flow
Module 2 - Section 1 - Controlling the flow
Completion requirements
View
After the completion of the this module the students will be able to:
- create code using the if statement
- recognize and use indented blocks of code
- solve Boolean algebra logic problems
- create code using the complicated if statements with elif and else
- recognize nested if statements and use them
2.1.5 - If and more If - Else if? or Else?
When we want to make a decision and from the outcome of the decision act then we use the if command.
Copy and paste the following code to the Thonny's editor and save it as temperature_decision.py inside your working folder.
As you can see inside the code there are three cases. One when temperature is greater than 30, one when temperature is lower than 12 and one in every other case.
Try the code using different temperature more than 30, between 12 and 30 and less than 12.
In the previous code , the program will output “It is hot outside” even if the user types in 70 degrees. Why? How can the code be fixed?
If you want to see a solution click here.