class logo

CS 122 - Quiz 3

Create a python program to solve the following problem

Here's my solution to the quiz: Problem 1 Solution

Posted Wednesday, August 12

Problem 1

Secret Number Guessing Game

I have created a game engine that implements the secret number guessing game as an Object. You need to write the front-end for the game -- the parts that ask the user for input and display the output. You must use the games.py module I have provided for you, and you may not modify it in any way. Your program must use the SecretNumberGame class to implement the secret number guessing game, and should also try to follow my user interface as closely as possible.

The game itself is the same secret number guessing game we have used previously in the term. One modification is that it now keeps track of the number of guesses the user has made, and prints that value when the user guesses the secret number correctly. Here is what the output should look like from a sample run of the game:

Guess a number between 1 and 10 (q to quit): 5 Too Low Guess a number between 1 and 10 (q to quit): 7 Too High Guess a number between 1 and 10 (q to quit): 6 Correct! It only took you 3 guesses!

And here's what another run would look like if the user entered a 'q' to quit after guessing once.

Guess a number between 1 and 10 (q to quit): 5 Too High Guess a number between 1 and 10 (q to quit): q Goodbye

 

The games.py module implements one class, the SecretNumberGame class. It requires no arguments when you create it, and provides the following methods:

submitAGuess(guess) Submits a guess to the game. The guess (an integer) is supplied as an argument.
guessIsTooHigh() Returns True if the last submitted guess was higher than the secret number, False otherwise
guessIsTooLow() Returns True if the last submitted guess was lower than the secret number, False otherwise
guessIsCorrect() Returns True if the last submitted guess was correct, False otherwise
getNumberOfGuesses() Returns the number of guesses that have been submitted so far

You can download my games.py module from this link. Don't forget to import the module in your program! You will not submit the games.py module when you turn in your program, I will just use the one I have created. Any changes you make to games.py won't be in my version, so don't make any changes to games.py.

Your grade will be based on:

  • Using the games.py module and SecretNumberGame object correctly
  • Matching the user interface in the examples above as closely as possible

Remember, this is an open note, open book quiz, you can use any available reference materials as you implement your solution.

Use this form to submit your quiz solutions. Note that just like an assignment, you can submit more than once if you realize that you made a mistake on a submission.

Student number (no dashes):
This is the 9-digit number on your student body card. It probably starts 950 or 951 and it looks something like this: 950123456. This number is used to identify your submission so please enter it carefully.
Name (first and last):
Email address:
Your solution to problem 1
Attach your python program that solves problem 1