Assignment 1

Due Midnight Wednesday

For this assignment, you will need to combine the two things we discussed in class today - error checking and our silly game.

So, to be very specific about this, I would like you to write a number guessing games that uses the random module to generate a random number between 1 and 100 (inclusive) and then tries to get the user to guess that number by providing the feedback "Too high" or "Too low". If the user guesses the exact answer, it should print out "Just right".

Furthermore, you should protect your code so that a user entering random garbage won't cause your program to crash. I demonstrated both of these things using actual working code in front of the class, so this shouldn't be too hard an assignment.

Here is a sample interaction with the program:

What number I am thinking of?
50
Too high
What number I am thinking of?
sdafasdf
What number I am thinking of?
4343 fsad asdf3
What number I am thinking of?
25
Too high
What number I am thinking of?
12
Too high
What number I am thinking of?
6
Too low
What number I am thinking of?
8
Too low
What number I am thinking of?
10
Just right

Either using the try: ... except: idea we discussed in class, or using the .isdigit() method that all strings have should be of great help. For extra credit, you may add features to the game to make it more interesting and fun - for example, you might add the ability to type "q" to quit, or 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.

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

Grade Distribution

0
1
2
3 0
4 0
5
6
7 0
8 0 0 5 5
9 0 5 5 5 7 9 9 9
10 0 1 2 5

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/06U/cis122/1.comment

Questions? Answers!
Valid CSS! Valid XHTML 1.1!