0% found this document useful (0 votes)
53 views8 pages

CSC 108H1 F 2009 Test 1 Duration - 35 Minutes Aids Allowed: None

This document is a test for a computer science course. It consists of 3 questions worth a total of 18 marks. Question 1 (worth 4 marks) involves functions, variables and image processing. Question 2 (worth 6 marks) asks the student to write a function to rotate the RGB values of pixels in an image. Question 3 (worth 8 marks) involves writing a program with a function to calculate and print a user's health insurance premium based on their income level. The document provides instructions, code snippets, and short descriptions of Python functions and methods to help the student answer the questions.

Uploaded by

examkiller
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views8 pages

CSC 108H1 F 2009 Test 1 Duration - 35 Minutes Aids Allowed: None

This document is a test for a computer science course. It consists of 3 questions worth a total of 18 marks. Question 1 (worth 4 marks) involves functions, variables and image processing. Question 2 (worth 6 marks) asks the student to write a function to rotate the RGB values of pixels in an image. Question 3 (worth 8 marks) involves writing a program with a function to calculate and print a user's health insurance premium based on their income level. The document provides instructions, code snippets, and short descriptions of Python functions and methods to help the student answer the questions.

Uploaded by

examkiller
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

CSC108H1 F 2009 Test 1

Duration 35 minutes
Aids allowed: none
Student Number:
Last Name: First Name:
Lecture Section: L0102 Instructor: Gries
Do not turn this page until you have received the signal to start.
(Please ll out the identication section above, write your name on the back
of the test, and read the instructions below.)
Good Luck!
This midterm consists of 3 questions on 8 pages (including this one). When
you receive the signal to start, please make sure that your copy is complete.
Comments and docstrings are not required except where indicated, although
they may help us mark your answers. They may also get you part marks if
you cant gure out how to write the code. No error checking is required:
assume all user input and all argument values are valid.
If you use any space for rough work, indicate clearly what you want marked.
# 1: / 4
# 2: / 6
# 3: / 8
TOTAL: /18
Total Pages = 8 Page 1 contd. . .
CSC108H1 F Test 1 Fall 2009
Question 1. [4 marks]
Suppose these functions have been dened:
import media
def do_something(left, right):
left = right
for pixel in left:
media.set_red(pixel, 0)
def do_stuff(a, b, c):
a = b + c
c = a + b
return a
The following code runs without errors. Fill in the boxes below to show the output printed or answer the
question, as indicated.
a = 145
one = 20
two = 25
one = do_stuff(a, one, two)
print a
output:
print one
output:
print two
output:
pic1 = media.load_picture(media.choose_file())
pic2 = media.load_picture(media.choose_file())
do_something(pic1, pic2)
media.show(pic1)
Does the picture that was just displayed have any red in it? Circle one: yes no
media.show(pic2)
Does the picture that was just displayed have any red in it? Circle one: yes no
Student #: Page 2 of 8 contd. . .
CSC108H1 F Test 1 Fall 2009
Question 2. [6 marks]
Write a function called rotate_rgb that takes a Picture as a parameter and, for every pixel, sets the
red value to the original green value, the green value to the original blue value, and the blue value to the
original red value.
You will need to use one variable for the parameter and one variable for the pixel values in the for loop.
You can earn the full 6 marks if you use only one more variable. If you use more than one, you can earn
at most 5 marks.
import media
Student #: Page 3 of 8 contd. . .
CSC108H1 F Test 1 Fall 2009
Question 3. [8 marks]
Write a program that uses raw_input to prompt the user for his or her income and then prints the amount
of health premium owed on that income. (A health premium is a kind of tax that is used to pay for health
coverage.) This program consists of two parts: a function named health_premium on this page and a main
block on the next page.
The health premium for a given income is computed as follows:
1. For less than $25,000 income, no premium is owed.
2. For incomes of $25,000 to less than $50,000, the premium is 5% of income.
3. For incomes of $50,000 or more, the premium on the rst $100,000 is 7%, and the premium on any
income above that is 10%. The total premium owed is the sum of those two values.
Your program should ask the user for input using the string Please enter your income: and print
the health premium owed as the string Your health premium is $XXX.YY. The amount printed should
be rounded to the nearest cent. XXX can be as many digits as it needs to be, YY must be 2 digits long,
and the total amount must be preceded by the character $.
def health_premium(income):
Return the health premium owed for a given income amount. The parameter
income is an int, and the health premium returned is a float.

Student #: Page 4 of 8 contd. . .


CSC108H1 F Test 1 Fall 2009
if __name__ == "__main__":
Student #: Page 5 of 8 contd. . .
CSC108H1 F Test 1 Fall 2009
[Use the space below for rough work. This page will not be marked unless you clearly indicate the part of
your work that you want us to mark.]
Student #: Page 6 of 8 contd. . .
CSC108H1 F Test 1 Fall 2009
Short Python function/method descriptions:
__builtins__:
abs(number) -> number
Return the absolute value of the given number.
max(a, b, c, ...) -> value
With two or more arguments, return the largest argument.
min(a, b, c, ...) -> value
With two or more arguments, return the smallest argument.
raw_input([prompt]) -> string
Read a string from standard input. The trailing newline is stripped. The prompt string,
if given, is printed without a trailing newline before reading.
float:
float(x) -> float
Convert a string or number to a float, if possible.
int:
int(x) -> integer
Convert a string or number to an integer, if possible. A floating point argument
will be truncated towards zero.
media:
choose_file() -> str
Prompt user to pick a file. Return the path to that file.
create_picture(int, int) -> Picture
Given a width and a height, return a Picture with that width and height. All pixels are white.
get_blue(Pixel) -> int
Return the blue value of the given Pixel.
get_color(Pixel) -> Color
Return the Color object with the given Pixels RGB values.
get_green(Pixel) -> int
Return the green value of the given Pixel.
get_pixel(Picture, int, int) -> Pixel
Given x and y coordinates, return the Pixel at (x, y) in the given Picture.
get_red(Pixel) -> int
Return the red value of the given Pixel.
load_picture(str) -> Picture
Return a Picture object from file with the given filename.
set_blue(Pixel, int)
Set the blue value of the given Pixel to the given int value.
set_color(Pixel, Color)
Set the RGB values of the given Pixel to those of the given Color.
set_green(Pixel, int)
Set the green value of the given Pixel to the given int value.
set_red(Pixel, int)
Set the red value of the given Pixel to the given int value.
show(Picture)
Display the given Picture.
Student #: Page 7 of 8 contd. . .
CSC108H1 F Test 1 Fall 2009
Last Name: First Name:
Page 8 of 8 End of Examination

You might also like