After the lab, you should be proficient at
for
loopsrandom
moduleWe'll practice writing several Python programs, each in their own text file. Name the files lab3.1.py through lab3.6.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.
Example output:
x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | ----------------------------------------------------------------------------------- 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 2 | 0 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | ... 12 | 0 | 12 | 24 | 36 | 48 | 60 | 72 | 84 | 96 | 108 | 120 | 132 | 144 |
for
loops, a variable with value "She
loves you," and another variable with value "yeah", print out the
Beatles lyrics:
She loves you, yeah, yeah, yeah She loves you, yeah, yeah, yeah She loves you, yeah, yeah, yeah Yea-aahh
elses
. Is this version better or worse than the previous
version? Think about how much work the computer has to do and the
control flow diagram (performance), and how easy it is for a human to
understand what is going on (readability). Write your thoughts in
comments.
To determine the winner for a game, generate a random number between -8 and 20, inclusive. If the number generated is positive, the Patriots (the first team) win. Otherwise, the Giants (the second team) win.
Style. For full credit, you must use constants for the name of each team, the minimum and maximum difference values, and the number of times you simulate the game. Using constants makes your program more generalizable.
Demonstration. Run your program at least once with 20 simulated games, which should require only one change to your program. Then, run your program again with 10 simulated games.
Example Runs:
Simulated Game 1 Patriots won Simulated Game 2 Giants won Simulated Game 3 Patriots won Simulated Game 4 Patriots won Simulated Game 5 Patriots won Simulated Game 6 Giants won Simulated Game 7 Giants won Simulated Game 8 Patriots won Simulated Game 9 Patriots won Simulated Game 10 Giants won ------------------------------ The Patriots are predicted to win 6 out of 10 times.
Simulated Game 1 Patriots won Simulated Game 2 Giants won Simulated Game 3 Patriots won Simulated Game 4 Patriots won Simulated Game 5 Giants won Simulated Game 6 Giants won Simulated Game 7 Giants won Simulated Game 8 Giants won Simulated Game 9 Patriots won Simulated Game 10 Patriots won ------------------------------ The simulation is inconclusive.
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 1:20
p.m. on Friday.
Ask well before the deadline if you need help turning in your assignment!