You should work on this lab with your partner and submit one Python program with both your names on it. The program should be submitted via email. It should consist of a single attachment which is one Python file. It should use comments to describe your project and to make the code more readable. (You should also include both your names in a comment atop your program file.) You and your partner will also be responsible for demonstrating your program to the class during our final group conference.
This lab departs substantially from previous ones. You will begin by experimenting with lists and simple graphics and doing some exercises which you do not need to submit. (You need to demonstrate the solutions to the exercises to either the instructor or the lab assistant.)
The crux of the lab is for you and your lab partner to design and implement a program that involves list, graphics, or, preferably, both.
You will need to submit, via email, with both your names on it, a program proposal within one week from this lab (April 29 or 30). You will then demonstrate a preliminary version two weeks from this lab (May 6 or 7); your final program will be due via email and to be demonstrated to the class in the final lab (May 13 or 14).
Examples programming projects:
A graphical version of nim. (Optionally use lists to keep track of who has won each game, at the end printing a list of the results.)
A phone book that allows the user to search and modify a list of names and phone numbers. (Optionally use graphics to allow user to click next to a name to see corresponding number.)
The game of hangman.
A simple drawing tool that lets the user select what kind of shape to draw and where to draw it.
Sequential search on lists. Write a function search_by_number that takes two arguments: a phone book and a number and returns the name that corresponds to that number. (If no such name exists. You can return the Python value None.) Example:
# initially, our phone book is the empty list:
my_phone_book = []
# we can then add pairs of names and numbers, each as short lists themselves
# we do this using the list "append" command:
my_phone_book.append(['Athena', 2161])
my_phone_book.append(['Xerxes', 1149])
my_phone_book.append(['Zeus', 7140])
# you can now see what it's in the phone book:
# >>> my_phone_book
# [['Athena', 2161], ['Xerxes', 1149], ['Zeus', 7140]]
# we can use sequential search
def search_by_number(phone_book, number):
... # fill in the details here!
return name
# testing it out:
>>> search_by_number(my_phone_book, 7140)
'Zeus'
Drawing simple shapes. Write a program that opens up a graphics window, draws a blue circle and a red rectangle.
Responding to mouse clicks. Modify your program so that the window closes if the user clicks on the window.
Animation. Modify your program so that each time the user clicks the window one of the shapes (your choice) moves a little bit to the right.
Polygons and lists of points. Write a program that opens up a graphics window and builds a list of points corresponding to where in the window the user has clicked. After five points, the program should draw a polygon connecting those points and display (in the normal interactions window) the coordinates of the five points.
(Optional) More challenging: modify one of your graphics programs so that each time you click on a shape (your choice which one) it changes color, cycling through a list of colors (for example, blue, then red, then green, then back to blue).