CS 115 Project 2, Fall 2016: Celebrating Democracy
Summary: In this project, you will graphically track the results of the presidential election, add up
the candidates' vote totals, and determine a winner.
Due dates:
- Checkpoint A: Due as a demo in workshop, lab, or tutoring hours before Monday Oct. 17 at 8PM
- Checkpoint B: Due as a demo in workshop, lab, or tutoring hours before Friday Oct. 28 at 3.30PM
- Final code: Due Tuesday, Nov. 8 (Election Day!) at 2 PM
Getting Started
Download the following files into your PyCharm directory for Project 02:
Read through the code in proj2_support_code.py carefully. PUT YOUR OWN CODE IN A SEPARATE FILE.
Do not modify proj2_support_code.py.
To use the Project 2 support code, put this line at the top of your Python file (just after the docstring):
from proj2_support_code import *
Checkpoint A (5 points)
For Checkpoint A, you will need to demonstrate a program that displays the following window:

Specifically:
- Your program should split the screen into two columns, one for Hillary Clinton and one for Donald Trump.
(You can choose which candidate comes first.) It should display the candidates' pictures at the top
center of each column.
- Just below each candidate's picture, you should print their vote totals. Initially, both totals will be 0.
- At the bottom center of the screen, display instructions to the user. These instructions should tell the user
to type a state abbreviation and then click one of the two candidates' pictures.
- Just below the instructions to the user, display an entry box that allows the user to type some text.
- Use the constants defined in proj2_support_code.py for the filenames, window dimensions, etc. The course
staff will check this as part of the demo process.
Hints:
- To display the candidates' pictures, use the Image functionality from graphics.py.
The documentation is here: http://mcsp.wartburg.edu/zelle/python/graphics/graphics/node13.html.
Here is some sample code that displays the contents of a made-up file called sample.gif centered
around the point (400, 400) in a window called win:
img = Image(Point(400, 400), "sample.gif")
img.draw(win)
- To display the vote totals and the instructions to the user, use the Text functionality from graphics.py.
The documentation is here: http://mcsp.wartburg.edu/zelle/python/graphics/graphics/node11.html.
Here is some sample code that creates a text box saying "Hello!" centered around the point (400, 400).
In this example, we save the text box to a variable so that we can change the text later if we want:
textbox = Text(Point(400, 400), "Hello!")
textbox.draw(win)
- To display the entry box, use the Entry functionality from graphics.py.
The documentation is here:
http://mcsp.wartburg.edu/zelle/python/graphics/graphics/node12.html.
Here is some sample code that creates an entry box 10 characters long centered around (400, 400):
entrybox = Entry(Point(400, 400), 10)
entrybox.draw(win)
The only way to get credit for Checkpoint A is to demo it for the course staff during workshop,
lab, or tutoring hours (or by appointment) before Monday, Oct. 17 at 8PM.
Checkpoint B (5 points)
Your Checkpoint B code needs to do the following:
The only way to get credit for Checkpoint B is to demo it for the course staff during workshop,
lab, or tutoring hours (or by appointment) before Friday October 28 at 3.30PM.
Final Code
In your final code, you will extend your Checkpoint B code in the following ways:
- Print a list of states that have not yet been counted to the center of the screen when your program starts. For example:

- As the user enters states, remove them from the list. In the example below, Donal Trump has won New York and Hillary Clinton has won California, so those two states have been removed from the list:

- If the user tries to re-enter a state that has already been counted, print an error message to the text window
using print. An example of such an error message is: "State Already Entered: NY " (Assuming user entered NY again in the entry box) .
- If one of the candidates has 270 or more votes, draw a big circle around his picture and draw an X through
the other candidate's picture. The support code has two functions you can call, circle_winner
and cross_out_loser. They both take two parameters: the graphics window and the center of the image
(as a Point). For example, to cross out an image centered at (400, 400), you would do cross_out_loser(win, Point(400, 400)). For balance, here is an example of each possible outcome:
- Wait for a mouse click before closing the graphical window.
- If the user closes the graphical window at any point before the winner is declared, your program must display an error message (example: "Window was manually closed - Restart the application") and exit cleanly.
In other words, your program should write code to handle the GraphicsError exception.
There is no demo for your final code. See the end of this specification for submission instructions.
Grading
Correctness [65%]
The most important part of your grade is the correctness of your final program.
Your program will be tested numerous times, using different inputs, to be sure that it
meets the specification.
A detailed grading sheet for this project is posted here.
Programming Design and Style [25%]
In addition to being correct, your program should be easy to understand and well documented. For details, see the grading sheet above.
Checkpoints [10%]
Your checkpoints are each worth 10 points, as described above. The checkpoints cannot be submitted late.
Extra credit [up to 5%]
There are lots of possibilities to extend this project for extra credit. If you have an idea you'd like to implement, run it by the instructor.
Submitting your final code
You should submit your final code on Moodle by the deadline. As a backup, I strongly encourage you to upload a copy to your blue directory in case something goes wrong with your submission to Moodle.
Please name your file yourlastnameP2.py, substituting your actual last name (in lowercase) as indicated.
Collaboration policy
Programming projects must be your own work, and academic misconduct is taken very seriously. You may discuss ideas and approaches with other students and the course staff, but you should work out all details and write up all solutions on your own. The following actions will be penalized as academic dishonesty:
- Copying part or all of another student's assignment
- Copying old or published solutions
- Looking at another student's code or discussing it in great detail. You will be penalized if your program matches another student's program too closely.
- Showing your code or describing your code in great detail to anyone other than the course staff or tutor.
Late policy
There is a 48-hour grace period associated with the final project deadline.
This grace period is designed to only cover small personal emergencies and other unexpected events.
No other consideration will be given for these small emergencies.