Chapter 4. Norwegian Blue parrot game: adding logic to programs
- Display an introduction
- Collect input from the user
- Use if statements to respond to users in different ways
- Use while loops to repeat things over and over
- Use Python code libraries to generate random numbers
Open a popular game, such as Minecraft, or think about a robot, like the Mars rover. Both are computer programs. What do they have in common? They both have the ability to take input and do something with it. What they do depends on the input they’re given. In a game, if you press Forward and fall off a ledge, your character falls and dies. If it’s your only life, then you’re taken to the Game Over screen. Similarly, the Mars rover might be instructed to go to a certain location, but if it detects a large rock in its way, it will stop or attempt to drive around the obstacle.
The logic of how games work or how the rover moves is programmed into them. But how do you create that logic in your programs? You’ll learn how by making a simple guessing game about a special parrot, the Norwegian Blue.