본문 바로가기

U of T: Computer Science/First Year: CSC108

CSC108 Assignment 1

CSC108/A08H Assignment 1

Introduction

The purpose of this assignment is to give you practice in a number of areas:

  • Fixing errors
  • Converting types
  • Functions
  • Image processing

Part 1: Removing red-eye

 

Download redeye.py. This program should modify an image file so that the reds are
changed to blacks; this will remove red eye. It contains indentation, syntax, and naming errors. Find and fix them, and submit the file. Given the top picture on the right, your program should produce the bottom picture on the right.

Don't worry about the fact that it changes other reds in the picture; just fix the errors. Later in the course you'll see another technique for removing red eye that only affects eyes.

Here is a picture with red eye.

Part 2: Converting imperial to metric

Recall that raw_input() will wait for a user to type something and then return what they typed. Write a program in file convert.py that allows a user to convert Imperial units (specifically, qt [UK], gal [UK], in, ft, and mi) to various metric units (specifically, ml, L, cm, m, and km). You can find all the conversions at the Online Conversion website.

Here is a sample interaction where user input appears in bold:

Imperial unit: galMetric equivalent: LValue to convert: 11 gal = 3.78541181 4.54609 L    

(You might get 4.5460900000000004 L depending on how you do it, but that's fine, too.)

It's easy to make a typing mistake, but your program doesn't have to deal with them: assume that the input will be correctly formatted, and will be an appropriate unit --- we won't, for example, ask to convert gallons to kilometers. Expect to convert both int and float values.

It's up to you to decide exactly what code to include in convert.py, but you must include a function named convert, which has three parameters, in this order:

  • a str representing the imperial unit (qt, gal, in, ft, mi),
  • a str representing the metric unit (ml, L, cm, m, km), and
  • an int or float representing the imperial value.

Function convert returns the metric value corresponding to the given imperial value and units of measurement. Include a docstring comment.

Part 3: Shapes, Colours, and More

In a file called a1.py, write the following functions. Include a docstring comment for each.

Function Name Description
rectangle_area(float, float) Given floats representing the width and height of a rectangle, in that order, return the area of the rectangle (as a float).
circle_area(float) Given a float representing the radius of a circle, return the area of the circle (as a float). (Module math defines a variable called pi that will be helpful.)
negative(Picture) Given a Picture, invert the picture by setting each pixel's red, green, and blue to their inverses: 255 - the colour value, and return the inverted picture (as a Picture).
change_brightness(Picture, int) Some pictures are too dark, some are too light. To brighten a picture, you can increase each of the red, green, and blue values, and to darken a picture you can decrease them. Write a function change_brightness that takes a Picture and a percentage amount to brighten the picture by. The percentage is in the range -100 to 100; a negative percentage indicates darkening and a positive percentage indicated brightening. For example, change_brightness(pic, -30) would reduce the red, green, and blue values by 30%, and change_brightness(pic, 20) would increase the red, green, and blue values by 20%. You'll encounter problems if this leads to a value larger than 255; don't just let it crash. Notice that if a picture is 100% brighter, all the values are doubled; it doesn't just turn all white. 100% darker, on the other hand, makes everything black.
bullseye() Return a 100 pixel wide by 100 pixel high picture of a bullseye with three rings: the outer ring has diameter 100 and is white, the middle ring has diameter 60 and is yellow, and the inner circle has diameter 20 and is red. There are functions in picture.py to help with this; in particular, look at make_empty_picture and add_oval_filled.

What to Hand In

Hand in the following files:

  • redeye.py
  • convert.py
  • a1.py

Student Solution

Teacher Solution

'U of T: Computer Science > First Year: CSC108' 카테고리의 다른 글

CSC108 Project  (0) 2007.12.16
CSC108 Assignment 4  (0) 2007.12.16
CSC108 Assignment 3  (0) 2007.12.16
CSC108 Assignment 2  (0) 2007.12.16
CSC 108 Course 소개.  (0) 2007.12.16