Please enable JavaScript to use CodeHS

AP Computer Science Principles in Python

Lesson 1.12 If/Else Statements

Description

In this lesson, students will take a deeper look into conditional statements, more specifically if/else statements. If/else statements allow for one thing to be done if a condition is true, and something else otherwise.

We write if/else statements like this:

if front_is_clear():
    # code to execute if front is clear
elif balls_present():
    # code to execute otherwise

Objective

Students will be able to:

  • Explain the purpose of an If/Else statement
  • Create If/Else statements to solve new types of problems
  • Identify when an If/Else statement is appropriate to be used