After the lab, you should be proficient at
random
modulegraphics.py
in /home/courses/cs111/handouts/lab3/
into
your lab3
directory.We'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.
clone
method to make a copy of the original
shape. Then draw the cloned shape in the window and move it to
the desired location.setCoords
method of
the GraphWin
object to adjust the coordinates of
the window. (See the reference above for more information
about setCoords
.)Screen Capture:
xv
, using the command xv
&
.You've saved the image!
Some previously created images to inspire you:
If you want to animate a group of objects, moving together, you
can use the GraphObjectGroup
class. There is an
example of using the GraphObjectGroup
class in
the example.py
file in
the /home/courses/cs111/handouts/lab3
directory. The example code may not make sense yet, but just
follow the example and ask questions.
if
statements (no elses
or
elifs)
to print "The Patriots
win" if the first number is bigger, "The Giants win" if the second
number is bigger, and "They tied! We're going to overtime!" if
the numbers are equal.elses
(no elif
s). 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.if-elif-else
structure instead. In comments, compare the readability
of the old version and the new version. (The efficiency of the
two programs is likely the same.)To determine the winner for a game, generate a random number between -6 and 8, inclusive. If the generated number is positive, the Patriots (the first team/AFC team) win. Otherwise, the Giants (the second team/NFC team) win.
Style. You should be able to easily modify this program to run next year (when the Dolphins and the Panthers are in the Super Bowl...). As discussed in class, using constants makes your program more generalizable and flexible. 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.
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.
Extensions. You're only a few weeks into programming, but you're already able to write a basic game simulator. In comments in code, describe 3 extensions you would make to this program to make the program "better", e.g., make it a more sophisticated simulation or more customizable or easier to use. What would be required for you to be able to implement those extensions? Time to implement it? Programming knowledge? Be specific about what constructs/knowledge you'd need to write your extended version.
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.
It's time to revisit our web pages. (You knew we'd get back to this sooner or later!)
public_html
directory.index.html
file into a file
called lab3.html
(in the public_html
directory).public_html
directory.lab3.html
in jEdit.turnin
directory.
(Review the UNIX handout if you don't
remember how to do that.)labs/lab3
directory;
otherwise, the print out will be long and screwed up. You can
move those files back into your lab3
directory
after you've printed. In other words, you should only have
the .py files you wrote and the .out files you created in your
directory when you print.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!