Programming Exercise 10

  < Previous  Next >

Due Date

See the calendar for due date.

Assignment:

You are tasked with developing a program that gets a random number, and then tries to guess it. The program should have a main() function that prompts a user for input that will be used as the seed to a random number generator. This main() function should then generate a random number between 1 and 100 inclusive and pass it to a function called randomGuess(r) where r is an integer. The randomGuess() function should then attempt to guess the random number argument. This should be accomplished by having the function initially guess a number from 1-100 where each guess is printed out. If the guess is correct, print a message. Otherwise, the program should determine if it is a high or low guess. The subsequent guess(es) should restrict the range based on this feedback. For instance, if the randomly chosen number is 33 and the initial guess is 50, the program should then limit the next guess to be between 1-49. Continuing, if the next guess is 10, the next guess would be restricted from 11-49. These guesses will continue until the number is guessed correctly.

Examples

The following are examples of correct execution (with the text in bold being the input from the user):
Please enter an integer to use as a random seed: 42
You entered 42
(psst, the random number is 82)
Guessing 50, but that was too low
Guessing 75, but that was too low
Guessing 87, but that was too high
Guessing 81, but that was too low
Guessing 84, but that was too high
Guessing 82, and that was correct!
Please enter an integer to use as a random seed: 4321
You entered 4321
(psst, the random number is 33)
Guessing 50, but that was too high
Guessing 25, but that was too low
Guessing 37, but that was too high
Guessing 31, but that was too low
Guessing 34, but that was too high
Guessing 32, but that was too low
Guessing 33, and that was correct!
Please enter an integer to use as a random seed: 7
You entered 7
(psst, the random number is 42)
Guessing 50, but that was too high
Guessing 25, but that was too low
Guessing 37, but that was too low
Guessing 43, but that was too high
Guessing 40, but that was too low
Guessing 41, but that was too low
Guessing 42, and that was correct!

Submission

Submit your python script using the handin program. For handin, for this lab, type the following in a terminal window exactly as it appears:
handin  pe10  pe10.py
To verify your submission, type the following in a terminal window:
handin  pe10