CS303E Project 4

Due Saturday, February 16 by 11pm

Write a program that plays a high/low guessing game with the user. The program should pick a random number between 1 and 100 (inclusive), and then repeatedly prompt the user to guess the number. After each guess, your program should print a message indicating whether the guess was high, low or correct. Prompt for guesses until either the user guesses correctly, or enters the value -1 as the guess. Keep track of the number of guesses and report this number when the user guesses correctly. You do not need to print anything when the user enters -1.

Note: You may not use any programming construct that we have not covered in class, including break. The code to select a random number is provided below:

number = random.randint(1, 100) # get a random number between 1 and 100

You will need to import the random package. Above your main method definition, include:

import random

Store your program in the file Guess.py

You may assume that the user enters valid input.

This is how your output should look. The user's inputs are in green.

Welcome to the High-Low Guessing Game!
Try to guess the number I've chosen between 1 and 100.

What is your guess? 50
50 is high.
What is your guess? 25
25 is low.
What is your guess? 37
37 is low.
What is your guess? 43
43 is high.
What is your guess? 40
40 is low.
What is your guess? 42
Correct! You only needed 6 guesses to get it!

Your output should look like the sample output above. You will lose credit if it does not.

Test your program by running it several times. Put 5 of your test runs and their output in comments at the end of your .py file

Name your file Guess.py. Be certain to begin your file with the following header:

# File: --name of file--
# Description: --a description of your program--
# Assignment Number:
# Name: --your name--
# EID: --your eid--
# Course Name: CS 303E
# Unique Number: --your section number--
# Date created:
# Date last modified:
# Slip days used this assignment:
# Total slip days used:

Use the turnin program to submit your file. The file must be turned in by February 16th at 11pm. If you use slip days, please notify your grader when you turn in your file. See the grading criteria that was posted on piazza.

Did you remember to: