After the lab, you should be proficient at
/home/courses/cs111/handouts/lab5/
into
your lab5
directory.We'll practice writing several Python programs, each in their own text file. Name the files lab5.1.py through lab5.5.py.
Your programs will be graded on correctness, style, efficiency, 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 lab5.x.out, where x is the problem number.
graphics
module, draw a yellow
circle with radius 30 and a red square of width 50 in a window
that is 400x200 with the name "Practice". Position the circle in
the upper-left quadrant of the canvas and the square in the
lower-right quadrant. There will be no IDLE output for this
program.
graphics
module, draw the beginning
of a snow-person. Create a canvas with the title "Snow Person".
Draw a white circle of radius 50. Clone the circle and
move the cloned circle above the first circle (so that the circle
appears to be sitting on top of the original circle). Repeat with
a third cloned circle. Draw two black, filled-in circles for eyes
in the top circle. Note that you should draw one eye, then clone
the eye and move it to the appropriate place. There will be
no IDLE output for this program.setCoords
method of
the GraphWin
object to adjust the coordinates of
the window. (See the reference 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/lab5
directory.
Enter the first word: zebra Enter the second word: monkey Enter the third word: pig The alphabetically first word is monkey
Enter the first word: dog Enter the second word: black cat Enter the third word: 13 The alphabetically first word is 13
Enter the first word: black Enter the second word: black cat Enter the third word: blacky The alphabetically first word is black
Since strings are immutable and given our current knowledge, you'll have to create a new string that contains all the characters except spaces from the original string. For full credit, only go through the string removing spaces if the string contains at least one space. Do not use a method to solve this problem.
Example output:
What is your string? The Beatles Your string without spaces is TheBeatles
What is your string? Help! Your string without spaces is Help!
public_html
directory.
index.html
file into a file
called lab5.html
(in the public_html
directory).
public_html
directory.
lab5.html
in jEdit.
turnin
directory.
(Review the UNIX handout if you don't
remember how to do that.)
labs/lab5
directory; otherwise, the print out will
be long and screwed up. You can move those files back into
your lab5
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. You should probably print from the
labs
directory.
Before you print, view the file to make sure it's not too long
or has weird characters in it from the .pyc
file. One
command to view the file is gv lab5.ps
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!