Programming Assignment 4
CS 303e

Covered topics:

nested loops
compound boolean conditions
String manipulation
functions

You may not use any programming constructs or concepts that we have not covered in class.

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.

The program should continue playing as long as the user says "yes", "sure" or "ok" when asked if (s)he wants to play.

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

```Do you want to play the game? yes Welcome to the High-Low Guessing Game! Try to guess the number I've chosen between 1 and 100. What is your guess? 15 15 is high. What is your guess? 4 4 is low. What is your guess? 8 Correct! You only needed 3 guesses to get it! Do you want to play the game? sure ```
```Welcome to the High-Low Guessing Game! Try to guess the number I've chosen between 1 and 100. What is your guess? 15 15 is low. What is your guess? -1 You stopped the game after 1 guess(es). Do you want to play the game? yes```
``` Welcome to the High-Low Guessing Game! Try to guess the number I've chosen between 1 and 100. What is your guess? 10 10 is low. What is your guess? 44 Correct! You only needed 2 guesses to get it! Do you want to play the game? nah ```
Submit your source file Guess.py by 11 pm on the due date. Make sure you include a comment header in your class that contains all required information (your name, EID, etc). See the lab 1 specification for a more detailed description of the required header.

Your code must contain 2 functions.
1. The main() function will ask the user (repeatedly), using a loop, if they want to play the game - if the player wants to play the guessing game, the function guessIt() will be called.

2. The guessIt() function will generate the random number between 1 and 100, read the user's guesses and provide feedback (i.e., high or low), and print a message indicating how many guesses were needed after the user is finished guessing.

We will discuss this in class, but you might also want to read the online documentation about the random.randint(a, b) method here.

Use the coding conventions we have discussed and used in class (eg, conventions for variable names) and include whitespace, comments and indentation to make your program more readable.

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

Programs that contain syntax errors will not receive any credit. Please plan ahead and allow plenty of time to get help from the TAs, proctors or instructor if you are having trouble with the program. Please do not email the course staff the day before the assignment is due if you need help - it is unlikely that we will respond quickly enough to assist you. Plan to come to the lab during office hours if you need help.

Save your program in a file called Guess.py. This program should include ample comments, and should use whitespace, indentation, and meaningful variable names to enhance readability. Include a header in your program as indicated in the description of project 1.

This program must be submitted by 11 pm on the due date in order to be considered on time. Please note in your program header how many slip days you used on this project, if any.

The proctors will be grading this project. IF you have any questions about grading, contact them first. If you submit this project late using slip days, you must email the proctors after your program is submitted and let them know that your project is ready to be graded.

This project must be done individually. You may talk to your classmates about solution approaches, but then you must write your own code.

Reminders - Did you remember to:
do this assignment by yourself?
use meaningful variable names?