Learn to Program Step-by-Step

Teachers Toolkit: Boolean Expressions

    Mouse in the Maze

    Word problems that use "and" and "or" can be confusing. In fact, sometimes the English we use is not the way we write the program. For instance a restaurant may say "We give a discount to children and seniors." But the program is testing one individual case and uses child OR senior. I often use this example to make the students aware of the language. I can use the mouse in the maze to present many examples in the time it takes to explain one word problem.

    Doors in the maze are represented by Boolean variable. True means the door is open, false if it is closed. Write the Boolean expression for when the mouse can escape.

    or and or

    A Nice Day

    When I teach if/else I usually have a conversation like the one below:
    Me: Is today a nice day?
    Student: Yes.
    Me: What makes it a nice day?
    Student: It not cold.
    Me: What temperature does it need to be to be a nice day?
    Student: 50
    Me: Exactly 50?
    Student: At least 50.
    Me: How do we say "at least 50" in C++?
    Student: temperature>=50
    Me: Good. Is that it? If it is greater than or equal to 50 then it's a nice day?
    Student: It can't be raining.
    Another student: And it can't be windy!
    Then we write the program. It doesn't always go as planned. I did that recently and the student answered, "Anything is better than yesterday."  Another student objected to the 50 degrees She said, "No, I'm sick of the cold! It has to be at least 80!"

    A Donut

    Child: Mommy, can I have a donut?
    Child: Can I have a soda?
    Mother: You can have a donut and a glass of milk, or soda.
    Child: OK! A donut and a glass of milk or soda.

    I ask the students, where did the mother put the parentheses? Where did the child put the parentheses?

    Everybody stand up!

    I was doing the letter grade from average using a nested if else. I had written
    if(average<65) letterGrade='F';
    else if(average<70) letterGrade='D';
    One student couldn't understand why I didn't need to say that the average was also >=65.

    Finally I said, "OK, Everybody stand up!"
    I asked all of the women to sit.
    I asked "Who is standing?"
    They said "Just the guys."
    Then I said, OK, I want the married men to sit.
    Can I just say "If you are married sit down." or do I need to say "Married men should sit."
    I continued the game, asking different groups to sit. (wearing glasses, take the bus, etc.)
    Each time I asked, "Who's still standing?"

    This web site, and all pages therein, are the sole property and responsibility of Zebra0.com.
    It is not endorsed, sponsored or provided by or on behalf of Montgomery College.

    Like us on Facebook:

    OER: Open Educational Resource
    Creative Commons License Author: Janet E. Joy; Publisher: Zebra0.com
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
    Creative Commons Attribution-NonCommercial 4.0 International License
    Last modified: March 18 2016 10:04:36.