Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me solve this game using PYTHON? Number Guess The number guessing game is a game where someone chooses a number and the

Can someone help me solve this game using PYTHON? Number Guess

The number guessing game is a game where someone chooses a number and the other person takes guesses at what number they choose. With each guess person one reveals if it was high, low or the correct number. Most people intuit after playing a few times that the best method is to half the guess each time. First guess 50, if thats high, then guess 25. Our program is going to simulate trials of different approaches to playing the game. The user wont be actually playing the game, but will instead tell the program how many trials they want to use against the different methods. The number to be guessed will be from 1- 100.

Different methods of playing. The computer will be the number guesser and the person who choose the number. For each round, the user needs to keep track of how many guesses it took with the given method. Once you have a total number of guesses we can calculate the average number of guesses per trial. For instance, if it took us 120 guesses over 10 trials, then our average is 12 guesses per trial to guess the correct number.

1. [Brute Force]. Start guessing at one, and each time we miss a guess we increment to the next number. We dont have to worry about if it was high or low since the number always has to be higher.

2. [Random]. Start guessing a random number between the current high and low. If the guess is to high, then the number just lower than that guess becomes the new high.

3. [Binary] Guess the number between the high and low. If its high, then the new high becomes one less than the guess. Continually guess the number directly between high and lows

4. [By 10]. Start guessing at 10, and increment by 10 each time it is still too low or not the right number. Then begin guessing one less once our guess is too high. If the secret number is 48, we start by guessing 10. Its too low so we guess 20, still too low, 30, then 40, then 50. 50 is too high so we try 49, still too high and then we guess 48 and its right. Taking us 7 tries to find the correct number

*FUNCTIONS

This is the first assignment that you have learned about functions and the use of them is required. They help making and debugging programs much easier. Break the problem down into smaller portions that you can solve and implement and test them in function form. Then you will find it easier to put them together like puzzle pieces to make the final solution.

*Requirements

Validate the number of trials, it must be greater than 0. (We dont have to worry about the user entering a non-integer at this point)

Run x many trials for the different methods and keep track of the total number of guesses then output the results formatted as shown below.

The number to be guessed each time will be between 1 and 100 After each trial a new number is chosen. Validate the users choice to run again. Be careful of case, YeS is also the same as YES. Development notes. Using. upper() will change all the characters to the given case. Making comparisons easier. It is ok for the user to enter it in lower case. We will upper case the value for them.

Break the program down into meaningful functions. Try to solve one problem at a time.

Example

Enter the number of trials -1

The number of trials must be greater than 0

Enter the number of trials 0

The number of trials must be greater than 0

Enter the number of trials 100 Method Guesses/Trial

===========================================

Brute Force 47.4444

Random 7.7980

Binary 5.9596

By Ten 10.5152

Do you want to run again? Y/YES/N/NO ==> e

You must enter Y/YES/N or NO only

Do you want to run again? Y/YES/N/NO ==> y

Enter the number of trials 50 Method Guesses/Trial =========================================== Brute Force 46.7551 Random 7.7755 Binary 5.8776 By Ten 10.0408 Do you want to run again? Y/YES/N/NO ==> n >>>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Second East European Symposium Adbis 98 Poznan Poland September 1998 Proceedings Lncs 1475

Authors: Witold Litwin ,Tadeusz Morzy ,Gottfried Vossen

1st Edition

3540649247, 978-3540649243

More Books

Students also viewed these Databases questions

Question

=+ Are these impediments caused by policy/procedure?

Answered: 1 week ago