6 Are you a mind reader?

 

This chapter covers

  • Checking if an input matches a value
  • Creating a while loop
  • Conditional logic with ‘if’ an ‘else’
  • Giving a different response based on a condition
  • Using else if (elif) and else to respond

A classic binary search guessing game (higher or lower), “I am thinking of a number between 1 and 100. Can you guess what it is?” You are then given five chances to guess the number correctly. Before you begin this chapter, you may want to challenge someone to play the game as a reminder about how it works. Or we can play, I am thinking of a number between 1 and 100, what is your first guess….!

WHAT YOU WILL BUILD

In this chapter you will build a version of the higher or lower number guessing game where a witch or other character of your choice has chosen a number between 1 and 100. They have given you five lives or chances to get it right, if you do guess correctly, then you are free to go. You have won. Unfortunately, if you do not guess the correct number in five tries, then you lose. On the positive side, if you do guess the number correctly, the witch will invite you to try again, if you dare! Figure 6.1

Figure 6.1 Can you guess the number and beat the witch?

Creating the project

Setting up the folder

Importing the modules

Creating the variables and choosing a random integer

Creating the main guessing function

Creating the ‘play again’ function

Building the main app

Running and Testing the GUI

Other things to try.

Extend the random number

Changing the number of lives

Cleanly exiting the App and program

Adding sound

Summary

sitemap