Tufts OpenCourseware
Author: Ming Y Chow

Tufts OpenCourseWare
Introduction to Game Development
M. Chow
Spring 2012



Lab 1: Practice with Python

This lab is worth 5 points. Instructions: Please complete the following set of programs. Please only use the following resources:

1. Write a program fizzbuzz.py that prints the numbers from 1 to 100. But for multiples of three print Fizz instead of the number and for the multiples of five print Buzz. For numbers which are multiples of both three and five print FizzBuzz. Yes, this problem comes from this classic article: http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html

2. Write a program called reverselist.py where you create a list of items and print it reversed. Please make this program as short as possible! For example, a list with three strings Tom, Dick, and Harry shall be printed:


3. Download list of historic places in the northeast region provided by the National Register of Historic Places: ne_landmarks.zip. Uncompress the ZIP to find a tab-delimited file ne_landmarks.txt. The list has 18,246 records. The file has four (4) columns:

  • Longitude
  • Latitude
  • Name (of historic place)
  • Info

Write a program word_count.py that counts the number of words in the file ne_landmarks.txt above. Your program must count how often each word appears in the file and prints:

word1 count1
word2 count2
word3 count3
word4 count4

Print the above list in order sorted by word. Store all the words as lowercase, so 'The' and 'the' count as the same word. The last line of the output will be the total number of words in the file (example: There are 576 words in this file.).

BONUS: Modify the Python program to count the number of words of any input file!

4. Write a class named Song (save it as Song.py). The idea is to keep track of a music collection. This class maintains organizational information about a song: title, artist, and album. The Song class must include the constructor def __init__ (self) and a method output(). You should have multiple parameters for your constructor method. Then, instantiate a few songs (of your own) and then call the output() method for each song that you create. Your output must be in the following format:

Title: "Mandy"
Artist: Barry Manilow
Album: Barry Manilow II

Title: "Where the Streets Have No Name"
Artist: U2
Album: The Joshua Tree