Unit 4 Lesson 7: Conditionals Practice (2024)


In this lesson students spend most of their time practicing using the skills and processes they have learned about conditionals. At the conclusion of the lesson students discuss the main things they realized and still have questions about at the conclusion of this lesson.


Students will be able to:

  • Write programs that use boolean expressions and conditional statements with the support of sample code.
  • Debug programs that use boolean expressions and conditional statements


This lesson is students primary opportunity to get hands on with conditionals in code prior to the Make activity in the following lesson. Give students as much class time as you can to work through these. For this lesson it's recommended that you place students in pairs as a support and to encourage discussion about the challenges or concepts they're seeing. In the following lesson students are encouraged to work independently.

Getting Started (5 minutes)


  • Today we're going to have a chance to practice programming with a lot of the concepts and patterns we've explored over the last two lessons. I encourage you to go through these with a partner, but pay close attention to what each other is doing. In our next lesson you're going to have to use a lot of these on an independent project, and these activities are good practice for what you'll find there! Alright, let's get to it!

Teaching Tip

Move Quickly to the Activity: There's a lot in the main activity of today's lesson. You may optionally wish to do a quick vocabulary review or address any questions that came up in the last lesson. Otherwise, give students more time to get hands on with some code.

Activity (35 minutes)

Group: It is recommended that students work in pairs for this lesson and a number of the activities feature discussion prompts. Consider using pair programming, having drivers and navigators switch every 3 minutes, not every project.

Open a Project: Direct students to open the Lesson7_App1 project. Students will start with this project, then move through each Lesson7 project until they finish with Lesson7_App9. Before students start, briefly remind them about debugging skills that they will be using in today's activity.


  • Today you're mostly going to practice what we've learned about programming with conditionals. As always you should be using the debugging process to help you as you work on issues. Today we're also going to be working on finding two types of errors:
    1. - Syntax errors show up when you type code that breaks the rules of the programming language. You can check for errors and warnings
    2. - Logic errors show up when you type valid code but it works incorrectly. Today you're going to focus on testing your code to make sure you don't have logic errors.
  • Other errors you may encounter include:
    • - Run-time error - a mistake in the program that shows when running the program. These are defined by the programming language.
    • - Overflow error - an error that occurs when a computer tries to handle a number outside of the defined range of values.

Projects 1-3: These levels only use the output command which prints commands in the debug console. Here are a few things to keep an eye out for:

  • Projects 1-2 ask students to write Boolean expressions using comparison operators. Students may need to quickly review the comparison operators (<, >, <=, >=, =, not=)
  • Project 4 asks students to write Boolean expressions with logical operators (and, or, not)

Teaching Tip

Providing Support: Circulate around the room through the lesson encouraging students to use the strategies introduced at the beginning of the lesson. Students have a number of supports at their fingertips, so a big part of your role is helping build their independence in using those resources.

Projects 4-8: These levels practice if-statements while working with a star color-changing app.

  • Projects 4-5 involve setting up an if-statement that becomes an if-else statement.
  • In Project 6 students follow a pattern to create a lengthy if-else-if statement.
  • For Project 7, make sure students understand what's happening. Students can use output statements in each of the if-else-if blocks to see which sections are triggering.
  • Project 8 demonstrates that Boolean expressions can be written as conditional statements, and vice versa

Project 9: This two-part project returns to the "Can I Adopt a Cat?" flowchart from the Conditionals Explore activity. Students will use the flowchart to work out the logic of the if-statements in a their program.

  • A new type of code appears in this project, cast. A cast is a special command that changes data from one type to another. Here, it's used to turn text into a number that can be used mathematically.
  • The second half of the project can be completed many different ways. There are different combinations of Boolean expressions using and and or. Students should regularly test their apps to see if their Boolean expressions are working properly.

Extension Opportunities

  • Project 3: Students can add more variables and create complex Boolean expressions. One challenge might be to assign a String to a variable and compare that string to another.
  • Project 9: There are multiple solutions. If students build their if-statement using only and encourage them to figure out how to build it using only or. They may need to switch the content of the if and else branches.
  • Project 9: Create another input (i.e. How many cats do you already own?). Students use this information to craft more complex if-statements.

Wrap Up (5 minutes)

Discuss: What aspects of working with conditionals do you feel like clicked today? What do you still feel like you have trouble with?

Teaching Tip

Discussion Goal: Use this opportunity to address any lingering questions or misconceptions in the room. You can also use this as a source of discussion topics to kick off the following lesson. As you lead the discussion, call out the many resources students have access to help when they're getting stuck.


  • Conditionals can be a little bit tricky, but I saw a lot of good progress today in nailing down this concept. We may have a few lingering questions, but you also have a lot of resources available. Next time you'll have a chance to put all this together by programming an app that starts with "the blank screen"!

Assessment: Check for Understanding

AP Reference: The questions below reflect how questions will be represented on the AP exam. You can use the AP CSP Reference Sheet and Quorum Info resource to see more about how the exam is presented and the differences between Quorum and the reference language.

Question 1

What will be displayed afer this code segment is run?

F (lives = 0){ DISPLAY("You Lose!")}ELSE{ IF ((score >= 5) AND (lives = 3)) { DISPLAY("Perfect Game!") } ELSE { DISPLAY("You Win!") }}

Choose one of the following:

  1. Perfect Game!
  2. You Win!
  3. You Lose!
  4. Nothing will be displayed

Question 2

The program below asks a user to type in a number and then will output a message. What number will a user need to input for the message "COLD" to be displayed?

number <- INPUT()IF (number >= 10){ IF (number <= 20) { DISPLAY("MEDIUM") } ELSE { DISPLAY("HOT") }}ELSE{ DISPLAY("COLD")}

Choose one of the following:

  1. 5
  2. 10
  3. 15
  4. 20

Standards Alignment

  • CSTA K-12 Computer Science Standards (2017): 2-AP-10, 2-AP-12
  • CSP2021: AAP-2.E.2
  • CSP2021: AAP-2.F.1, AAP-2.F.2, AAP-2.F.3, AAP-2.F.4
  • CSP2021: AAP-2.H.2, AAP-2.H.3
  • CSP2021: AAP-2.L.3, AAP-2.L.4
  • CSP2021: AAP-3.A.9
  • CSP2021: CRD-2.I.1, CRD-2.I.2, CRD-2.I.3, CRD-2.I.4
  • CSP2021: CRD-2.J.2

Next Tutorial

In the next tutorial, we will discuss CSP Unit 4 Lesson 8 Conditionals Make, which describes Make an app using conditionals.

Go BackNext Tutorial

Unit 4 Lesson 7: Conditionals Practice (2024)
Top Articles
Latest Posts
Article information

Author: Gregorio Kreiger

Last Updated:

Views: 6299

Rating: 4.7 / 5 (57 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Gregorio Kreiger

Birthday: 1994-12-18

Address: 89212 Tracey Ramp, Sunside, MT 08453-0951

Phone: +9014805370218

Job: Customer Designer

Hobby: Mountain biking, Orienteering, Hiking, Sewing, Backpacking, Mushroom hunting, Backpacking

Introduction: My name is Gregorio Kreiger, I am a tender, brainy, enthusiastic, combative, agreeable, gentle, gentle person who loves writing and wants to share my knowledge and understanding with you.