After the lab, you should be proficient at
random
moduleWe'll practice writing several Python programs, each in their own text file. Name the files lab3.1.py through lab3.7.py.
Your programs will be graded on correctness, style, and how well you tested them. Make sure you adhere to the good development and testing practices we discussed in class. Your code should be readable and your output should be useful and well-formatted.
After you've developed a correct solution to each program, restart IDLE or close and reopen the IDLE "shell" by running the program again (using F5), demonstrate that the program works using several good test cases, and save the output to a file named lab3.x.out, where x is the problem number.
elses
. Is this version better or worse than the previous
version? Think about how much work the computer has to do
(performance), and how easy it is for a human to understand what is
going on (readability). Write your thoughts in the comments.
and
operator in the
condition for an if statement. Take a number as input and print
``Eureka!'' if the number is between 500 and 1000, inclusive;
otherwise, print ``Your number (< the number >) is out of
range.''
not
and a pair of parentheses to reverse the behavior of your program.
The Rules
The player keeps rolling until one of two things happen. Either the player makes the point and wins, or the player rolls a 7 and loses (craps out). Any number other than the point or 7 is of no consequence.
After the first roll, print a message that tells the player that they either won, lost, or which "point" they have to play for.
Example runs:
*** This program simulates Craps (without the betting) *** You rolled a 11 Congratulations! You win! |
*** This program simulates Craps (without the betting) *** You rolled a 6 The POINT is 6 Roll again! You rolled 4 Roll again! You rolled 6 Congratulations! You win! |
*** This program simulates Craps (without the betting) *** You rolled a 10 The POINT is 10 Roll again! You rolled 4 Roll again! You rolled 9 Roll again! You rolled 7 Sorry! You crapped out. Luckily, money wasn't involved. |
Simulate a game of Rainbow Dice, a Sprenkle family tradition. (Note that this will be fairly easy after you implemented the Craps game.)
turnin
directory.
(Review the UNIX handout if you don't
remember how to do that.)
printLab.sh
command.
Again, you should probably print from the labs
directory.
Print the file using the lpr
command introduced in the
first lab.
Labs are due at the beginning of Friday's class. You should hand
in the printed copy at the beginning of class, and the electronic
version should be in the turnin
directory before 2:25
p.m. on Friday.
Ask well before the deadline if you need help turning in your assignment!