Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Previous problem: Please write code in python programming language 1 Algorithms for High/Low Guessing Game In this problem, you will implement and analyze two algorithms

image text in transcribed
image text in transcribed
Previous problem:
image text in transcribed
Please write code in python programming language
1 Algorithms for High/Low Guessing Game In this problem, you will implement and analyze two algorithms for playing the guessing game from Tutorial 0. In both algorithms, you must keep track of the lower () and upper (u) bounds and use these bounds to generate the next guess Gi+1). 1.a Random Guesses Perhaps the simplest strategy, you generate a random number between I, and u, which be- comes guess git Depending on the feedback, either too low or too high, you adjust the bounds and repeat. Hint: Start with uo 100 and lo 0. Let gi be the first guess. Likewise, let l and u be the updated bounds after the first guess Do the following: D Write pseudocode. Include both the guessing algorithm (the player) and the game rules (see Tutorial 0). Print out each guess instead of asking for keyboard input. Implement in Python. Make a function that takes the secret number as its input and returns the number of guesses. O Test your code with 50 as the secret number. 1.b Bisection A more intuitive strategy is the bisection algorithm. It cuts the search space in half each iteration using the guess gi (4 + ui)/2, where I and u, are the (updated) lower and upper bounds, respectively, after guess i. Do the following: O Write pseudocode. Include both the guessing algorithm (the player) and the game rules (see Tutorial 0). Print out each guess instead of asking for keyboard input. Implement in Python. Make a function that takes the secret number as its input and returns the number of guesses. O Test your code with 50 as the secret number. 1.c Analysis Use your two functions, compare both strategies for the following secret numbers: 1,43, 76, 89. For each secret number value: O Play the game 100 times using the random strategy O Create a histogram showing the number of guesses to win with the random strategy O Compare the number of guesses with bisection strategy versus the average number of Create a histogram showing the guesses with the random strategy 1.d Discussion In a few sentences, interpret the results from both. Which strategy is better? Offer justifica- tion for why your results are not surprising. Write pseudocode and Python program to interactively play the following game: 1. Generate a random integer number between 0 and 100. 2. Ask the player to guess a number. Capture their input from the keyboard. 3. Check if the number is valid (between 0 and 100, integer). If not, warn the player and goto Step 2. 4. If the player's guess is correct, they win. Print out "Congratulations" and tell them how many guesses it took. Only count valid guesses. Terminate the program. 5 o lowit es to lo" and goho 2 6. If the guess is too high, print "Guess is too high." and goto Step 2 First write the pseudocode and then implement in Python. Test your program a few times. Submission Instructions: D Prepare your solutions in a Juypter Python notebook. Tip: Use Colaboratory D Embed a photo/scanned image of your handwritten pseudocode. Add extensive comments to your Python code

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

Microsoft Outlook 2023

Authors: James Holler

1st Edition

B0BP9P1VWJ, 979-8367217322

More Books

Students also viewed these Databases questions