Discovering Conditions in Python: Making Smart Decisions!
Learning objective
Discovering Conditions in Python: Making Smart Decisions!
Learning objective
Learning Objective
At the end of the lesson, you'll understand how to use conditions in Python to make decisions in your code.
What Are Conditions?
Conditions let programs make decisions. They ask 'if' something is true or false, then decide what to do next.
The 'if' Statement
An 'if' statement checks if a condition is true. If true, it runs the code inside.
The 'else' Statement
'Else' provides an alternative action if the 'if' condition is false.
Using 'elif'
'Elif' checks another condition if the previous 'if' or 'elif' was false.
Comparing Values
Use ==, !=, >, <, >=, <= to compare values in conditions.
Interactive Exercise
Try creating an 'if-elif-else' statement to decide what to wear based on the weather.
Homework Assignment
Create a program that asks for a number and tells if it's positive, negative, or zero using conditions.
Write down 3 things you learned in this lesson.
Write down 2 things you want to know more about.
Ask 1 question about something you haven't quite understood yet.