## Guess The Number

### January 17, 2012

We previously wrote a program to provide small exercises in arithmetic for children just learning their basic facts. Today’s exercise is similar; it plays a guessing game where children compete against the computer to see which can guess the number faster. Here’s a sample dialog:

```Let's play Guess-The-Number! You go first. I am thinking of a number from 1 to 100 What is your guess? 38 My number is less than your guess. What is your next guess? 15 Your guess is less than my number. What is your next guess? 25 Your guess is less than my number. What is your next guess? 33 My number is less than your guess. What is your next guess? 28 Your guess is less than my number. What is your next guess? 31 Your guess is less than my number. What is your next guess? 32 You guessed my number 32 in 6 tries! Now it's my turn. Think of a number from 1 to 100. Is your number less than 50? Yes Is your number less than 25? No Is your number less than 37? Yes Is your number less than 31? No Is your number less than 34? Yes Is your number less than 32? No Is your number less than 33? Yes I guessed your number 32 in 7 tries. You made less guesses than me. You win! Congratulations! Would you like to play again? No Thanks for playing! Good-bye!```

Your task is to write a program that plays Guess-The-Number; the maximum number in play (100 in the sample dialog) should be a parameter to the program. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Pages: 1 2
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}