## CS 1401
Introduction to Computer Science

Fall 2012
Test 1, TR 12-1:20 pm class section, October 9, 2012

Name: __________________________________________________________
1. What is the value computed by each of the following
arithmetic expressions in the Python language?

9 / 10

9 + 1 / 10

9 / 1 / 10

9 / 10.0

2. For each of the following programs, trace the code and
list all the points that will be colored (and by what color)
by this program:

# program a
im = Raster()
x = 9
y = 10
while y <= 12:
im.set(x,y, orange)
x = x + 1
y = y + 2
# program b
im = Raster()
x = 9
y = 10
while y <= 12:
im.set(x,y, orange)
x = x + 1
y = y + 2
# program c
im = Raster()
x = 9
y = 10
while y <= 12:
im.set(x,y, orange)
x = x + 1
y = y + 2
# program d
im = Raster()
x = 9
for y in range(10,12):
im.set(x,y, orange)
im.set(x+5,y, blue)
# program e
im = Raster()
x = 9
for y in range(10,12):
im.set(x, y, orange)
im.set(x+5, y, blue)
# program f
im = Raster()
x = 9
for y in range(12,10):
im.set(x, y, orange)
im.set(x+5, y, blue)
# program g
im = Raster()
for y in range(10,12):
for x in range(x, x + 2):
if y < 12:
im.set(y,x, orange)
else if y < 13:
im.set(y,x, blue)
else:
im.set(y,x, white)

3. A student who turns in his or her research report by Monday
October 15 can potentially receive full credit (10 points),
while a student
who turns in the report by October 8 gets extra points, so he or
she can receive 13 points. Define a function *points(date)*
that, given a date in October, returns the number of points.
Write down a code that uses
this method to compute the number of points for today (i.e., for
*date* = 9).

4. Define a function *vertical(image, x, color)* that draws, in a
given image, a full vertical line of a given color
at a given x coordinate.

5. Use a nested loop to draw a white box that covers all
the points to the left of the vertical line at a given x coordinate.