Boolean variables are used to track a true or a false (similar to a ‘yes’ or ‘no’).
Remember our game? We could use a boolean variable to track if the game has finished or not. When the game starts, we could assign the variable to an initial value like this:
game_over = False
When the user runs out of lives, the following code could then set this variable to true so that the program knows that the game is over:
game_over = True
We have mentioned the most common variable data types, those that are common to many languages. Now lets review what we have learned so far in this lesson.
Codey has been locked out of their goal. Can you find a way to unlock it using the
doorLocked variable can be found under the
Set command dropdown. Set it using the teal boolean value box.
Set doorLocked to false Move Down Move Down