Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Guessing game instructions from Tutorial 0 (rules from previous assignment): Please write code in python programming language. I have already written code for tutorial 0
Guessing game instructions from Tutorial 0 (rules from previous assignment):
Please write code in python programming language.
I have already written code for tutorial 0 but am having trouble with implementing bounds.
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 (I) and upper (u) bounds and use these bounds to generate the next guess (g+). 1.a Random Guesses Perhaps the simplest strategy, you generate a random number between 4 and u which be- comes guess 9i+1. Depending on the feedback, either too low or too high, you adjust the bounds and repeat. Hint: Start with o 100 and lo 0. Let gi be the first guess. Likewise, let /i and u1 be the updated bounds after the first guess. Do the following: 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 D 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 9i+1(4 +ui)/2, where I and u are the (updated) lower and upper bounds, respectively, after guess i. Do the following: 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. D Implement in Python. Make a function that takes the secret number as its input and returns the number of guesses. 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: Play the game 100 times using the random strategy. Create a histogram showing the number of guesses to win with the random strategy. Compare the number of guesses with bisection strategy versus the average number of guesses with the random strategy. 1.d Discussion 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. If the guess is too low, print "Guess is too low." and goto Step 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: 1 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 codeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started