1 of 28

Lesson 9

Conditionals

Foundations of AI Programming

2 of 28

Warm Up

3 of 28

  • If the description fits you, then stand up.
  • If not, then stay seated.

Do This:

Foundations of AI Programming Conditionals Warm Up

4 of 28

Let's Review: Algorithms

An algorithm is a set of instructions to accomplish a task. This usually includes:

      • Sequencing: steps in order
      • Selection: making decisions
      • Iteration: repeating steps

Foundations of AI Programming Conditionals Warm Up

5 of 28

Which component of an algorithm did you just experience when you either stood or stayed seated?

Discuss:

Foundations of AI Programming Conditionals Warm Up

6 of 28

  • Explain what a conditional statement does and when to use one in a program.
  • Write if statements in Python to control program flow.
  • Identify and fix common errors in if statements.

Lesson Objectives

By the end of this lesson, you will be able to . . .

Foundations of AI Programming Conditionals Warm Up

7 of 28

How can we use conditional statements to help a computer make decisions?

Question of the Day

Foundations of AI Programming Conditionals Warm Up

8 of 28

Activity

9 of 28

if isabel.can_move("south"):

isabel.move()

isabel.paint("blue")

if isabel.can_move("south"):

isabel.move()

isabel.paint("blue")

Foundations of AI Programming Conditionals Activity

10 of 28

if isabel.can_move("south"):

isabel.move()

isabel.paint("blue")

if isabel.can_move("south"):

isabel.move()

isabel.paint("blue")

Foundations of AI Programming Conditionals Activity

11 of 28

You should have:

  • Foundations of AI Programming Unit Guide
  • pen or pencil

Unit Guide

Foundations of AI Programming Conditionals Activity

12 of 28

A conditional statement tells a computer to do something only if a certain condition is True.

if painter.can_move("south"):

painter.move()

painter.paint("blue")

📝 Unit Guide

What is a Conditional Statement?

Foundations of AI Programming Conditionals Activity

13 of 28

1

if isabel.can_move("south"):

2

isabel.move()

3

isabel.paint("blue")

📝 Unit Guide

Foundations of AI Programming Conditionals Activity

14 of 28

1

if isabel.can_move("south"):

2

isabel.move()

3

isabel.paint("blue")

📝 Unit Guide

Foundations of AI Programming Conditionals Activity

15 of 28

1

if isabel.can_move("south"):

2

isabel.move()

3

isabel.paint("blue")

📝 Unit Guide

Foundations of AI Programming Conditionals Activity

16 of 28

1

if isabel.can_move("south"):

2

isabel.move()

3

isabel.paint("blue")

📝 Unit Guide

Foundations of AI Programming Conditionals Activity

17 of 28

1

if isabel.can_move("south"):

2

isabel.move()

3

isabel.paint("blue")

📝 Unit Guide

Foundations of AI Programming Conditionals Activity

18 of 28

Why do you think conditionals are useful in programs? What kinds of decisions might a program need to make?

Discuss:

Foundations of AI Programming Conditionals Activity

19 of 28

Do This:

Exploring Conditionals

1

Lesson 9

  1. Go to Lesson 9, Level 1.
  2. Complete Levels 1 through 4 to explore how to use if statements.
  3. Complete the Check Your Understanding on Level 5.

Foundations of AI Programming Conditionals Activity

20 of 28

What did you learn about if statements?

Discuss:

Foundations of AI Programming Conditionals Activity

21 of 28

What questions do you still have about if statements?

Discuss:

Foundations of AI Programming Conditionals Activity

22 of 28

What are the benefits of using if statements in our code?

Discuss:

Foundations of AI Programming Conditionals Activity

23 of 28

UMPIRE

Remember to use the UMPIRE strategy as you work on using conditionals within your programs.

U

M

P

I

R

E

Understand

Make a plan

Produce

Inspect

Refine

Explain

Foundations of AI Programming Conditionals Activity

24 of 28

Do This:

Decisions with the Painter

6

Lesson 9

  • Go to Lesson 9, Level 6.
  • Complete Levels 6 and 7 to solve problems using if statements.
  • Complete the Check Your Understanding on Levels 8 and 9.

A

B

C

D

Foundations of AI Programming Conditionals Activity

25 of 28

Wrap Up

26 of 28

  • What a conditional statement does and when to use one in a program.
  • Writing if statements to control program flow.
  • Identify and fix common errors in if statements.

Today, you learned about . . .

Foundations of AI Programming Conditionals Wrap Up

27 of 28

How can we use conditional statements to help a computer make decisions?

Question of the Day

Foundations of AI Programming Conditionals Wrap Up

28 of 28

  • conditional statement: tells a computer to do something only if a certain condition is True

Key Vocabulary

Foundations of AI Programming Conditionals Wrap Up