Computer Science 222, Laboratory 6 – Graphics
- Use Python
methods for reading text files with numeric data.
- Use the
author-supplied graphics package.
programs graphics.py and graphics22.py. (We have found that on some machines graphics
works better, and on other machines graphics22 works better. We aren't sure why this is
so.) Try both graphics packages and use the one that works better. For
each of the following, demonstrate your code to the instructor.
Part I. Files with Numeric Data.
1. Hourly Raise.
Each line of the file hourlyWages.txt contains information about employees for
some company in the form:
Each employee is getting a raise of $1.65 per
hour. Write a program hourlyWages.py that reads in each line of the file and
calculates each employee’s new pay for the week. The program should then output each
employee’s first and last name and pay for that week to the file newHourlyWages.txt. Format the pay to two places after the
Part II. Graphics.
2. Playing with Graphics.
Download the program Discussion3.py that is on pp. 159-60 of the text. Do programming
Exercise 1 on p. 160. Make sure that the center of the square is at the point
where the user clicks. Call your program squares.py.
3. Drawing a target.
Do Programming Exercise 2 on p. 160. Call your program
4. Building a rectangle from its corners.
Do Programming Exercise 9 on p. 161. Display
the numerical output in the graphics window – don't use print. Call your program rectangle.py.
5. Drawing a circle from its center and radius.
Write a program called circle.py to draw a
circle. Make the window size 400 by 400. The first mouse click determines the
center of the circle. The second mouse click determines a point on its
circumference. Use the Euclidean distance formula to determine the length of
Ask the user to
click to end the program, and be sure to close the window at the end.
Upload the files to both
student accounts (don't forget to submit):
squares.py ______ target.py ______
rectangle.py ______ circle.py ______
Delete any files that you have put on the desktop.
Empty the trash. Log off the computer.
You'll get 1 file (48.7KB)