Lesson 4: Booleans and Logic

Overview

Booleans are the fourth and final data type that students will learn about in this course. In this stage, students will learn about Boolean (true/false) values, and explore how they can be used to evaluate logical questions.

Agenda

Getting Started

Activity

View on Code Studio

Anchor Standard

Common Core Math Standards

  • 7.EE.4 - Use variables to represent quantities in a real-world or mathematical problem, and construct simple equations and inequalities to solve problems by reasoning about the quantities.

Objectives

Students will be able to:

  • Evaluate simple Boolean expressions.
  • Evaluate complex Boolean expressions.

Preparation

  • 3x5 cards

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the Teacher

Support

Report a Bug

Teaching Guide

Getting Started

Booleans - True or False?

What types of data have we used in our programs so far?

  • Can you think of Number values?
  • String values? Image values?
  • What are some expressions that evaluate to a Number?
  • How about the other datatypes?

What would each of the following expressions evaluate to?





The last expression, (3 < 4), uses a new function that compares Numbers, returning true if 3 is less than 4. What do you think it would return if the numbers were swapped?

The function < tests if one number is less than another. Can you think of some other tests?

Functions like <, > and = all consume two Numbers as their Domain, and produce a special value called a Boolean as their Range. Booleans are answers to a yes-or-no question, and Boolean functions are used to perform tests. In a videogame, you might test if a player has walked into a wall, or if their health is equal to zero. A machine in a doctor’s office might use Booleans to test if a patient’s heart rate is above or below a certain level.

Boolean values can only be true or false.

Activity

Boolean 20 Questions

Give each student a card and have them answer the following questions on it (feel free to add some of your own)

  1. What is your hair color?
  2. Do you wear glasses or contacts?
  3. What is your favorite number?
  4. What is your favorite color?
  5. What month were you born?
  6. Do you have any siblings?
  7. What is the last digit of your phone number?
  8. What is something about you that people here don't know and can't tell by looking at you?

Then collect the cards and shuffle them. To play the game, follow these steps:

  • Select a card
  • Say: I’m going to read the answer to #8 but if it is you, don’t say anything.
  • Say: Now everyone stand up and we are going to ask some questions with Boolean answers to help determine who this person is.
  • Begin the following true/false questions. Preface each one with “If you answer false to the following question, please sit down.” The person whose card you are reading should always answer true so you will need to change the example questions below. For this example, the answers were:

  • What is your hair color? - brown

  • Do you wear glasses or contacts? - yes
  • What is your favorite number? - 13
  • What is your favorite color? - blue
  • What month were you born? - December
  • Do you have any siblings? - yes
  • What is the last digit of your phone number? - 7

With that example, you might make the following statements:

  • My hair color is brown.
  • I wear contacts or glasses. (you only have to answer true to One of these to remain standing)
  • My favorite number is greater than 10 and less than 20. (you must answer true to both these.)
  • My favorite color is blue or green.
  • I was not born in April.
  • I have at least one sibling.
  • The last digit of my phone number is a prime number.

Because of how numbers 3,4, 5, and 7 were asked it is likely that some people will still be standing. You will need to revisit these and ask them again in a more narrow fashion such as “My favorite color is blue”.

Play this several times. Be creative with using _or_s and _and_s. Remind students that the OR means that either part of the statement being true will result in the entire statement being true. In English, an “or” is often an “exclusive or” such as “You can have chicken or fish.” In English, you only get to pick one, but with Boolean logic you could have chicken, fish, or both!! For the example person above, “I was born in December OR my favorite number is 13” is true. Note that “I was born in December AND my favorite number is 13” is also true.

Have a student try to act as the quizmaster after several rounds. If a mistake is made by you, a student quizmaster, or the person whose card you are reading, see if you can analyze where the mistake was made or why the question being asked might not have been clear.

How does this activity connect with our game? In our game, we may need to determine: Is a target too far left or too far right? If so, then perhaps some action should occur.

  • Levels
  • 1
  • (click tabs to see student view)
View on Code Studio

Student Instructions

Standards Alignment

View full course alignment

Common Core Math Standards

EE - Expressions And Equations
  • 6.EE.9 - Use variables to represent two quantities in a real-world problem that change in relationship to one another; write an equation to express one quantity, thought of as the dependent variable, in terms of the other quantity, thought of as the independent va
F - Functions
  • 8.F.1 - Understand that a function is a rule that assigns to each input exactly one output. The graph of a function is the set of ordered pairs consisting of an input and the corresponding output.1
  • 8.F.2 - Compare properties of two functions each represented in a different way (algebraically, graphically, numerically in tables, or by verbal descriptions). For example, given a linear function represented by a table of values and a linear function represented
MP - Math Practices
  • MP.1 - Make sense of problems and persevere in solving them
  • MP.2 - Reason abstractly and quantitatively
  • MP.3 - Construct viable arguments and critique the reasoning of others
  • MP.4 - Model with mathematics
  • MP.5 - Use appropriate tools strategically
  • MP.6 - Attend to precision
  • MP.7 - Look for and make use of structure
  • MP.8 - Look for and express regularity in repeated reasoning
NS - The Number System
  • 6.NS.1 - Interpret and compute quotients of fractions, and solve word problems involving division of fractions by fractions, e.g., by using visual fraction models and equations to represent the problem. For example, create a story context for (2/3) ÷ (3/4) and use
OA - Operations And Algebraic Thinking
  • 5.OA.1 - Use parentheses, brackets, or braces in numerical expressions, and evaluate expressions with these symbols.
  • 5.OA.2 - Write simple expressions that record calculations with numbers, and interpret numerical expressions without evaluating them. For example, express the calculation “add 8 and 7, then multiply by 2” as 2 × (8 + 7). Recognize that 3 × (18932 + 921) is three t
Q - Quantities
  • N.Q.1 - Use units as a way to understand problems and to guide the solution of multi-step problems; choose and interpret units consistently in formulas; choose and interpret the scale and the origin in graphs and data displays.
  • N.Q.2 - Define appropriate quantities for the purpose of descriptive modeling.
REI - Reasoning With Equations And Inequalities
  • A.REI.10 - Understand that the graph of an equation in two variables is the set of all its solutions plotted in the coordinate plane, often forming a curve (which could be a line).
  • A.REI.3 - Solve linear equations and inequalities in one variable, including equations with coefficients represented by letters.