1 of 10

Computer Science in Math

2 of 10

Booleans

Getting your program to ask the right questions

3 of 10

Vocab

  • Boolean - a type of data with two values: true and false
  • Return - used as a synonym for output of a function.

4 of 10

Types of Data

  • What types of data have we used in our programs?
    • What are some examples of Number values?
      • 25, ⅓, -42, 90.3
    • What are some examples of String values?
      • “Hello”, “25”, “outline”, “purple”
    • What are some examples of Image values?

5 of 10

What type of data do these return?

6 of 10

A New Data Type!

  • (3 < 4) states “3 is less than 4”
  • The block returns true
  • What if we swapped the arguments?
  • “4 is less than 3” would return false
  • true and false are called boolean values
  • What other math functions might return booleans?
  • < (less than), > (greater than), = (equal to)

7 of 10

20 Questions!

On a 3x5 card, answer the following questions

    • What is your hair color?
    • Do you wear glasses/contacts?
    • What is your favorite number?
    • What is your favorite color?
    • What month were you born?
    • How many siblings do you have?
    • What is the last digit of your phone number?
    • What is something that your classmates don’t know about you and could tell just by looking at you?

8 of 10

20 Questions!

  • Everyone stand up
  • I’m going to read the answer to #8 but if it is you, don’t say anything.
  • Using only questions that return a boolean (yes/no) value, we’re going to try and figure out whose card was picked
  • If your answer to a question is false, sit down

9 of 10

Combining Boolean Questions

  • You can combine or modify boolean functions using and, or, and not
  • And returns true if both of its parameters are true
    • (10 > 6) and ( 6 > 2) - True!
  • Or returns true if either of its parameters are true
    • (10 > 6) or ( 2 > 6) - True!
  • Not returns true if its parameter is false
    • not (6 > 10) - True!

10 of 10

20 (more) Questions!

Now play the boolean 20 questions game again, but this time use and, or, and not in your questions!