Date

Due: Wednesday, September 21, 11:00 AM

Write a program called higher_lower.py to play a simple guessing game with you.

The computer will pick a number between 1 and 100, then give you 5 guesses. If you guess right, it will say "You win!". If you guess higher or lower than correct, it will say "The number is higher than that." (or lower). If after five guesses they still don't know the number, print "You lose; the number was x." where x was the number you were to guess.

Before the game begins, ask what number to pick. If they say "−1", pick randomly; otherwise, use their number even if it is outside the 1–100 range. Check your notes for how to get a random integer by using the random.randint() method.

An example run of the program might look like:

What should the answer be? 19
Guess a number: 9
The number is higher than that.
Guess a number: 40
The number is lower than that.
Guess a number: 19
You win!

Another run might look like:

What should the answer be? -1
Guess a number: 5
The number is higher than that.
Guess a number: 100
The number is lower than that.
Guess a number: 50
The number is lower than that.
Guess a number: 25
The number is lower than that.
Guess a number: 12
You lose; the number was 7.

You do not have to use loops to make the program work. If, however, you know how to use loops or would like to try, you may do so.

Submission: Please submit one .py file named higher_lower.py to the POTD submission system at https://archimedes.cs.virginia.edu/cs1110/.