14
Lesson 14 of 20 ยท Conditionals
Conditionals โ Part 3
Ifโelse: make decisions based on conditions. This is part 3 of 20.
What you'll learn
You will learn how if/else lets code make decisions based on whether something is true or false.
Steps
- 1Read the code. x is set to True. The 'if x:' line checks: is x true? Since it is, the code prints 'Yes!'
- 2The 'else' block only runs when the condition is NOT true. Since x IS True, the 'No!' line gets skipped entirely.
- 3If x were False instead, the computer would skip 'Yes!' and print 'No!' instead. One condition, two possible paths!
- 4Conditions let programs make decisions โ like a fork in the road. 'if' goes one way, 'else' goes the other.
Key Terms
- Condition
- A check that can be true or false. The program chooses what to do based on it.
- if
- A keyword that means 'when this is true, do this block of code.'
- else
- A keyword that means 'otherwise, when the if is not true, do this block instead.'
Python 3
Output
Loading Python... This may take a few seconds.
Your code runs only in your browser. No code is sent to any server. Stay safe and have fun learning!
๐จ๏ธView in Shop
Checkout complete lesson on Conditionals for 3rd Grade
Get the full Conditionals track as a printable PDF โ all lessons, worksheets, and answer keys.
