If Statements
In the Python programming language, if statements allow you to write code that only runs sometimes.
Dependencies
Students need to have these skills before learning this skill:
Goal
When you teach this skill, your goal is to make it so that students can write code that looks like this:
name = input("What is your name? ")
if name == "Perry the Platypus":
print("Curse you Perry the Platypus!")
Activities
Here are some activities that you can do in order to teach this skill.
Writing on the board
-
Write this code on the board:
favorite_color = input("What is your favorite color? ")
if favorite_color == "Orange":
print("That’s my favorite color too!") -
Ask students what they think that code is going to do.
-
After calling on a few students, reveal the correct answer.
-
Ask all students to write similar code on their computers. Their code should ask a different question an react to a different answer.
-
Have students run their code in order to make sure that it works.