Boolean Logic

March 7, 2022

A Short Intro to Boolean Logic  

One foundation of programming is Boolean logic, named for mathematician George Boole https://wiki.kidzsearch.com/wiki/George_Boole. It creates streamlined decisions, reducing a choice with lots of options to one with only two options. Boolean logic may sound advanced, but it isn’t difficult to introduce to students with games and discussion points, and once they get the hang of it, they’ll be able to create more intricate conditionals in their code.  

Boolean Logic in an Everyday Situation 

If you’re not already comfortable with Boolean logic, or if you’ve never tried talking about it on a kid’s level, here’s an everyday situation using it: a smoothie shop with different fruits in the menu.  

Would you like a mango smoothie? Maybe peach? Raspberry? Banana? Strawberry? Orange? Our human brains can sort through options and arrive at a choice, even if they are all presented together like a menu. But for a program, each action must be taken one step at a time.  

 

        Would you like a mango smoothie (yes/no)? 

        If no, go to the next flavor. 

        Would you like a peach smoothie (yes/no)?  

        If no, go to the next flavor. 

        Would you like a raspberry smoothie (yes/no)? 

 

Here’s a short program showing this that you or your students can copy.  This is created in Python, using IDLE, which you can download free here:  

https://www.python.org/downloads/ 

When you run this, you’ll get a list of each flavor in the menu, one at a time until the user types “yes.” 

 

 

 

Notice that if you type anything other than y-e-s, the program will continue listing fruits. This is because it isn’t checking for “yes” or “no,” it’s checking for “yes” or “anything but yes.” This subtle difference is important. 

  

 

 

True and false 

Coding uses the terms “True” or “False” in the context of Boolean logic to show that something in the program either is or is not. As an English sentence, the if statement in that program would say:  

 

     The variable “smoothie_order” is the same as the word “yes.” 

 

That statement either is (making it True) or is not (making it False). To a human reader, the code is asking about smoothie flavors, but to the program, all that matters is if y-e-s is stored in the variable. 

 

Here’s another code sample that shows this a little more explicitly (pay attention to the = symbols). This program displays True or False by comparing your variable to some other value.  

 

    

Combining Statements with the Boolean Operators 

Look at these sentences: 

        I ordered a mango smoothie. (True) 

        I ordered a dragonfruit smoothie. (False) 

 

You can add another layer to this with the words AND, OR, and NOT. These are called the Boolean operators. They combine multiple statements into a single True or False one (video link https://www.youtube.com/watch?v=MDAZkcRSF8Y&t=57s ).  

 

  • I ordered a mango smoothie AND a dragonfruit smoothie. (False)
  • I ordered a mango smoothie OR a dragonfruit smoothie. (True) 
  • I ordered a mango smoothie NOT I ordered a dragonfruit smoothie. (True) 

          Awkward grammar, but I ordered mango. I did not order dragonfruit.  

  • I ordered a dragonfruit smoothie NOT I ordered a mango smoothie. (False) 

          The order matters with the NOT operator. 

 

Games and Brain Break Activities That Reinforce Logic Gates 

The principle of Boolean logic is great for side activities to boost your students’ critical thinking skills. Check out the list below for fun ways to break up a day while reinforcing computational thinking. 

 

  • Robot
    • Students must write instructions for a robot (you or another student) to complete an assignment (i.e., cross the room and open the door). They must use specific commands instead of regular speech (i.e., walk, turn, and grab), and a maximum number of instructions (i.e., no more than five). Add Boolean operators to the commands for more difficult assignments (i.e., open a box full of papers and choose a specific one).  

 

  • Guess Who / Twenty Questions 
    • Play these games in a digital classroom by providing a list of names or facts on a website, like mathematicians or famous programmersThe goal is to ask the fewest questions, so students must choose their words carefully. Show how the Boolean operators can help with sample questions like: “Is the person you’re thinking of a woman AND a scientist?” “Is this a person from the USA OR someone who wears glasses?”

 

  • Make a Quiz
    • Have your students write quizzes together that incorporate the Boolean operators, and see if you can stump each other! Start easy with questions like “We live on planet Earth AND unicorns are real. (True or False?)” Then try advancing the complexity: “The sun is in the sky AND clouds are in the sky OR fish are in the sky. (True or False?)”  

 

What other activities can you think of? 

Have you ever explained the concepts of True and False to students?  

What techniques did you use? 

 


Author

Written by Bethany Goossen, curriculum writer and coding teacher with Best Brains Learning Centers.