This assignment asks you to write two programs in Python. As before, you can do this assignment either in the computer lab or on your own computer, if you have one.
This is an old child's game. Suppose Alice and Bob play together. Each makes a hand in the shape of a rock (a fist), a sheet of paper (a flat hand), or a pair of scissors (index and middle fingers extended, and the rest closed). If both make the same shape, the game is a draw. If not, the winner is determined as follows:
If Alice makes the shape of a rock, and Bob the shape of a sheet of paper, Bob wins ("paper wraps rock").
If Alice makes the shape of a rock, and Bob the shape of a pair of scissors, Alice wins ("rock smashes scissors").
If Alice makes the shape of a sheet of paper, and Bob the shape of a pair of scissors, Bob winas ("scissors cut paper").
Your job: write a program to let you play this game against the computer. Your program's output is to look like that in the "Sample Run" below. Don't worry if you can't duplicate the "rock", "paper", and "scissors" words n exactly that order; they are generated randomly. But aside from that, and the name (use your own name, please), everything else should be the same.
There are lots of ways to do this, so we won't give you step-by-step instructions. But here are some suggestions.
Don't forget to greet the player, and say goodbye.
In what follows, what I typed is black; what the computer typed is blue (just like in the IDLE GUI).
What is your name? Matt Hello, Matt Matt says paper, computer says scissors: computer wins! Do you want to play again (yes/no)? yes Matt says rock, computer says scissors: Matt wins! Do you want to play again (yes/no)? yes Matt says scissors, computer says rock: computer wins! Do you want to play again (yes/no)? yes Matt says paper, computer says paper: Draw! Do you want to play again (yes/no)? what I'm sorry, I only understand yes or no. Do you want to play again (yes/no)? yes Matt says rock, computer says scissors: Matt wins! Do you want to play again (yes/no)? no Thank you for playing, Matt
In class, you saw that trying to convert a string that contained non-digits to an integer using the conversion function int() caused your program to stop running (the technical term is "crash"). We're going to tackle this in two parts. This week, you'll write a program that will tell you whether you typed an integer or not, without crashing.
First, what is an integer? An integer is a string of (decimal) digits, specifically "0", "1", "2", "3", "4", "5", "6", "7", "8", and "9", with possibly a leading "+" or "-" sign. There may be white space (blanks or tab characters) both before and after it. So, determining if an input string is an integer is the same as stripping off leading and trailing blanks, seeing if the first character is a "+" or a "-" sign or a digit, and the rest are digits. That's the outline of your program.
Here it is, with a bit more structure:
Again, there are many ways to do this program, so please be creative! But your output should match the output in the Sample Run below exactly.
Because your program is to check only one number at a time, we ran ours several times to get the following output. Each time we ran it, the "RESTART" line, and the prompt beneath it, appeared.
Here, what the program output is in blue, what we typed is in black, and the portions from the IDLE GUI are in red. You don't need to duplicate the red parts.
Type your input: 27 The integer you typed is 27 >>> ================================ RESTART ================================ >>> Type your input: 345 The integer you typed is 345 >>> ================================ RESTART ================================ >>> Type your input: -345 The integer you typed is -345 >>> ================================ RESTART ================================ >>> Type your input: - 345 You didn't type an integer >>>
To hand everything in, create a ZIP file named lab8.zip containing the three python files. In the labs, you can use the FilZip utility to create the ZIP file. Go to Start, then to All Programs, then to Utilities, then to FilZip. In FilZip, go to File, then to New Archive, and create lab8.zip on the Desktop. Click the Add (+) button and select the files. Note that you must click two Add buttons before they are added to the archive. Save your zip file in MySpace, and also submit it to MyUCDavis.