Skip to Main Content

Coding for Educators

Boolean Logic

BOOLEAN

Computer programs make decisions based on conditionals. Conditional statements always evaluate to either TRUE or FALSE. This is called Boolean Logic.

Humans make decisions all day every day based on conditions. For example, if it is cold outside where a jacket, else don't where a jacket. What is another example?

By creating conditional statements we can control what statements execute, when they execute, and for how long.

The Town of Bool​

1) Read the story from Computional Fairy Tales page 30.

2) How does a boolean AND statement evaluate to TRUE?

3) How does a boolean AND statement evaluate to FALSE?

4) How does a boolean OR statement evaluate to TRUE?

5) How does a boolean OR statement evaluate to FALSE?

6) What does a boolean NOT statement do?

 

Creating Boolean Conditions

Comparison Operators

 

Comparison Operators

Flip a coin

Use micro:bit to create a program that flips a coin.

1) We will need to generate a random Boolean Variable of TRUE or FALSE.

2) Create a decision structure that displays an icon on the LED if TRUE else displays a different icon on the LED.

3) Add a repeat statement before the IF statement to simulate an animation of a coin toss.

Roll a die

Use micro:bit to roll a die

1) Use Shake event to simulate rolling a die.

2) Generate a random number 

3) Use the random number with an IF statement to show the correct # of dots on the LED.

HINT: Use Duplicate to write your code quicker

Rock, Paper, Scissors Game

Use the micro:bit to simulate Rock, Paper, Scissors

1) Use the On Shake event 

2) Based on a random display a picture of either a Rock, a Paper, or Scissor on the LED Panel.

3) Play against someone else in the class.

Add additional features

4) Every time you win a round press the A button to keep your increase your score.

5) When the B button is pressed your total score should be displayed.

6) Play 3 rounds with someone else in the class to determine a winner.