# CodeStepByStep

## guessing_game

Write a console program in which the program thinks of a random integer and the user tries to guess it. After each incorrect guess, tell the user whether the correct answer is higher or lower.

A series of guessing games is played. In each game, the computer chooses a random number between 1 and 100 inclusive. The game asks the user for guesses until the correct number is guessed. After each incorrect guess, the program gives a clue about whether the correct number is higher or lower than the guess. Once the user types the correct number, the game ends and the program reports how many guesses were needed.

After each game ends and the number of guesses is shown, the program asks the user if he/she would like to play again. Assume that the user will type a one-word string as the response to this question. A new game should begin if the user's response starts with a lower- or upper-case Y, such as "y", "Y", "yes", "YES", "Yes", or "yeehaw". Responses of "no", "No", "okay", "0", "certainly", and "hello" are all assumed to mean no.

Once the user chooses not to play again, the program prints overall statistics about all games. The total number of games, total guesses made in all games, average number of guesses per game (as a number rounded to the nearest tenth), and best game (fewest guesses needed to solve any one game) are displayed.

```This program allows you to guess random numbers.
I will think of a number between 1 and 100
and you will try to guess it.
After each guess, I will give you a clue about
whether the correct number is higher or lower.

I'm thinking of a number between 1 and 100...
It's lower.
It's higher.
It's lower.
It's higher.
It's lower.
You got it right in 6 guesses!
Do you want to play again? y

I'm thinking of a number between 1 and 100...
It's higher.
It's lower.
It's lower.
You got it right in 4 guesses!
Do you want to play again? YES

I'm thinking of a number between 1 and 100...
It's lower.
It's higher.
It's higher.
It's higher.
It's lower.
It's higher.
You got it right in 7 guesses!
Do you want to play again? no

Overall results:
Total games   = 3
Total guesses = 17
Guesses/game  = 5.7
Best game     = 4
```

You should handle the special case where the user guesses the correct number on the first try. Print a message as follows:

```I'm thinking of a number between 1 and 100...
You got it right in 1 guess!
```

In order to match the expected outputs in our logs, use the `randint(min, max)` function to produce random numbers. On each game, randomly choose a single integer from 1 to 100 to represent the correct answer.

Assume valid user input. When prompted for numbers, the user will type integers only, and they will be in proper ranges.

You should break down your program into several functions that use parameters and returns to exchange data.

Define a class constant for the maximum number used in the games. The previous log shows games from 1 to 100, but you should be able to change the constant value to use other ranges such as from 1 to 50 or any maximum.

(Because this problem uses random numbers, it is difficult to exactly match the expected output. To match our output, you must use `random.randint` to generate random numbers between 1 and the max.)

Complete program: Write an entire program that you could put into a file and run outside of CodeStepByStep.