Week 4
Guessing Game
A random integer, and two conversations that ask again when the input is bad.
First a level, then guesses.
Silence for a bad guess. A comparison for a real guess, until it matches.
The question, more slowly
The question is two conversations. First, ask for a level until you have a positive integer. Then pick one secret integer from 1 through that level, both ends included. Then ask for guesses. A guess that is not a positive integer is ignored, with no message. A real guess is too small, too large, or exactly right, using the words in the spec.
Level 1 has only one possible secret, so the only positive guess is correct. A guess above the level is too large. A guess of zero or a word is not a guess at all.
People use a random range that excludes the top end, so the level itself is never chosen. The lecture's integer function includes both ends. Also, do not print an error for a bad guess. Just ask again.
Before you code
Roll a die in the toy on this week's page. Notice that both ends can come up. The secret number works the same way, from 1 through the level.