6 Are you a mind reader?

 
06_00

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?
06_01
06_01a

6.1 Creating the project

6.1.1 Setting up the folder

6.1.2 Importing the modules

6.1.3 Creating the variables and choosing a random integer

6.1.4 Creating the main guessing function

6.1.5 Creating the ‘play again’ function

6.1.6 Building the main app

6.1.7 Running and Testing the GUI

6.2 Other things to try.

6.2.1 Changing the random number

6.2.2 Changing the number of lives

6.2.3 Adding sound?

6.3 Statements of fact

sitemap