Exercises for Lesson 14

Back to Lesson 14

Exercise 0: Creating interesting images

What does the following code do? How would you change it to do that to rows instead?

def createImage(w, h):
    """
    Creates a wxh image with an interesting pattern.

    returns: the image
    """
    image = Image(Point(0,0), w, h)

    for col in range(w):
        num1 = min(col, 255)

        for row in range(h):
            color = color_rgb(num1, num1, num1)
            image.setPixel(col, row, color) 

    return image

Back to Lesson 14

Exercise 1: Reading from a CSV file

Assume you have a file names.csv with the following format:

Colin,1
Therese,15
Sadie,12
Hobbes,7
Lulu,7

Write a program that reads in the file and prints a message for each user:

>>> main()
Hi Colin, you are 1 year(s) old.
Hi Therese, you are 15 year(s) old.
Hi Sadie, you are 12 year(s) old.
Hi Hobbes, you are 7 year(s) old.
Hi Lulu, you are 7 year(s) old.

If you have time, think about how you can tailor the message to print “year” or “years”, as appropriate.

Back to Lesson 14