April 2024
Beginner to intermediate
500 pages
24h 20m
English
We are now ready to write our Guess a Number game. Listing 2.3 shows our first pass at the game with the secret number being between 1 and 100.
Listing 2.3 Guess a Number, pass 1
In this program, we first set the start and end values to 1 and 100, respectively. Then we print a message to the user explaining the game. Next, in lines 8 to 10, we generate the first guess and ask the user to respond. This primes the while loop, whose condition is that the user does not respond with “correct.” Inside the while loop, we check whether the user’s response was “too high,” in which case we adjust the end variable ...
Read now
Unlock full access