If Statements in Python: Making Decisions with Code

If Statements in Python: Making Decisions with Code
1 / 13
next
Slide 1: Slide

This lesson contains 13 slides, with interactive quizzes and text slides.

Items in this lesson

If Statements in Python: Making Decisions with Code

Slide 1 - Slide

This item has no instructions

Learning Objective
At the end of the lesson, you will be able to write and use if statements in Python to make decisions in your code.

Slide 2 - Slide

Introduce the learning objective and explain why it's important for students to learn if statements.
What do you already know about decision-making using code?

Slide 3 - Mind map

This item has no instructions

What are If Statements?
If statements are used to make decisions in code. They allow your program to take different actions based on whether a condition is true or false.

Slide 4 - Slide

Explain the concept of if statements and provide a simple example.
Syntax of If Statements
The syntax of an if statement in Python is:
if condition:
code to execute if condition is true

Slide 5 - Slide

Explain the syntax of if statements and provide an example.
Using Comparison Operators
To create conditions in if statements, you can use comparison operators such as == (equal), != (not equal), > (greater than), < (less than), >= (greater than or equal to), and <= (less than or equal to).

Slide 6 - Slide

Explain the different comparison operators and provide examples.
Else Statements
Else statements allow you to provide an alternative action to take if the condition in the if statement is false. The syntax is:
if condition:
code to execute if condition is true
else:
code to execute if condition is false

Slide 7 - Slide

Explain the concept of else statements and provide an example.
Elif Statements
Elif statements allow you to specify additional conditions to check if the first condition is false. The syntax is:
if condition:
code to execute if condition is true
elif condition2:
code to execute if condition2 is true
else:
code to execute if all conditions are false

Slide 8 - Slide

Explain the concept of elif statements and provide an example.
Nested If Statements
You can also nest if statements inside other if statements to create more complex conditions. The syntax is:
if condition1:
if condition2:
code to execute if both conditions are true

Slide 9 - Slide

Explain the concept of nested if statements and provide an example.
Practice Problems
Practice using if statements by completing the following problems:

Slide 10 - Slide

Provide practice problems for students to complete and encourage them to ask questions if they need help.
Write down 3 things you learned in this lesson.

Slide 11 - Open question

Have students enter three things they learned in this lesson. With this they can indicate their own learning efficiency of this lesson.
Write down 2 things you want to know more about.

Slide 12 - Open question

Here, students enter two things they would like to know more about. This not only increases involvement, but also gives them more ownership.
Ask 1 question about something you haven't quite understood yet.

Slide 13 - Open question

The students indicate here (in question form) with which part of the material they still have difficulty. For the teacher, this not only provides insight into the extent to which the students understand/master the material, but also a good starting point for the next lesson.