CMPS 5P Introduction to Programming in Python Programming Assignment 3 solution

$20.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (2 votes)
In this assignment you will write a Python program that plays an interactive guessing game with the user.
Your program will generate a random integer in the range 1 to 10, then allow the user three guesses to
determine the integer. After each guess your program will inform the user whether the guess was correct, too high, or too low. Your source file for this project will be called . Here is a transcript of
several plays of the game. The symbol stands for the command line prompt and is not typed by the user.
Observe that there are blank lines at the beginning and end of program output, and blank lines separating
guesses. Your program should match the above format exactly.
Use the method in the module to generate the random number. You can read about this
module and it’s availabe methods in the Python module index.
https://docs.python.org/3/library/random.html#module-random
2
Once the mystery number is chosen, program operation will depend on user input. Your program must give
truthful responses to the user’s guesses then halt when either the right number is guessed, or the user runs
out of guesses. You will use the conditional operations to accomplish this. These
commands will be discussed at length in class, and can also be found in chapter 5 of the online text. What to turn in
Submit your program , to the assignment name before the due date. As always start early
and ask questions in lab sessions, office hours, and on piazza.
Discussion
Although this game is very simple, it is interesting to consider what strategy the user might adopt. Try to
verify for yourself that if we were to allow four guesses instead of three, then a strategy exists that would
find the mystery number with certainty, i.e. the guesser could always win. Similarly if we were to restrict
the number to the set {1, 2, 3, 4, 5, 6, 7}, then it can always be found in three guesses. The game, as defined
above, does posses an optimal strategy (optimal in the sense that it maximizes the probability winning.)
Try to deduce such a strategy, and show that by using it, the guesser will win 70% of the time. As an
exercise, write a program that plays the other side of the game (i.e. the role of guesser) and that implements
this optimal strategy. This exercise will yield no credit for the current assignment, but it may form the basis
of some future (more difficult) project.