if
Python · Unit 2: Conditionals
- Full plan
- Python
- 10 exercises
if asks a question. If the answer is True, it runs the line below; if it is False, it skips it.
The if line ends with a colon (:).
temp = 90
if temp > 80:
print("It is hot")Prints
It is hot
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Predict the output
What does this code print?
2. Complete the code
Finish the
ifline.3. Predict the output
What does this code print?
4. Predict the output
What does this code print?
5. Complete the code
If the money is enough, you buy. You have 80 and it costs 80. Fill in the condition.
6. Find the bug
It should warn you when it is cold. Which line has the error?
7. Find the bug
It should take off 50 and say "Discount applied" only when the cart is over 500. Which line has the error?
8. Put the lines in order
The person types 20. Put the lines in order to say whether they can get into an R-rated movie.
9. Multiple choice
What does this code do?
10. Predict the output
What does this code print?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.