Assignment 1

Due Midnight Thursday

For this assignment, you will need to make a robust version of the "guess the number" game. It should be robust to bad input, and it should select a random number between 1 and 100 (inclusive) as the answer. If the user tires of the game, then they should be able to quit early by typing the word 'quit' instead of a number.

You should use the random module to generate a random number between 1 and 100 (inclusive), and the code we discussed today and the .isdigit() method should be helpful for the error checking.

Also, I recommend building the game piecewise. I've been trying to do this in class, but I've been quiet about it. Get a game with a subset of the features working, then add features one by one and make sure each feature works in turn. This helps ensure that you are working on a stable and correct foundation. When you try to build something all at once, it's hard to know where the problem is when it doesn't work. When it used to work, and you only changed a few things, then discovering the source of any problems is much easier.

Here is a sample interaction with the program:

Guess a number between 1 and 100
Type 'quit' to exit early
50
Too high
-sdfg
That is not a number or the word 'quit'.  Please try again.
asdf
That is not a number or the word 'quit'.  Please try again.
324-fasd
That is not a number or the word 'quit'.  Please try again.
123-23
That is not a number or the word 'quit'.  Please try again.
1e2
That is not a number or the word 'quit'.  Please try again.
1e+2
That is not a number or the word 'quit'.  Please try again.
1.2
That is not a number or the word 'quit'.  Please try again.
25
Too high
12
Too high
6
You win!
Thanks for playing

Here's another sample interation:

Guess a number between 1 and 100
Type 'quit' to exit early
quit
Goodbye
Thanks for playing 

For extra credit, you may add features to the game to make it more interesting and fun - for example, you might have the computer randomly add or subtract one from the target number, so that it is always a bit of a moving target, or you might add the ability to do negative numbers, or the ability to play multiple games without having to restart the program.

Good luck, and don't hesitate to contact me with questions. If you post comments and questions below, then everyone else can read the question and answer and hopefully we will all become less confused over time.

Boilerplate

Ask me if there are any questions, and remember that elegance counts! peter@cs.uoregon.edu, or simply commenting below will all reach me immediately. Also recommended is coming in to office hours if you have any questions.

Turn It In

Turn your project in using the following form:

What is your student #?
What is your name?
What is your email?
What file would you like to submit?
If you have more than one file in your project, please use an archiving tool to put them all into one archive file. Acceptable archive types are .zip, .jar, .tar, and .tgz.

Please make sure that you provide any README files in plain text. MS Word .doc files are not acceptable. .html, .txt, .ps, .dvi, and .pdf are all acceptable. Really you should just be turning in ASCII text (.txt) files and source code. And for most assignments, just well documented source code.

Comments and Clarifications

The admin should touch /cs/classweb/07U/cis122/1/index.comment

Questions? Answers!
Valid CSS! Valid XHTML 1.1!