This assignment is Homework 13, and is due at classtime on Wednesday, March 29.

Assignment

  1. Do Files Exercise #1 from the online Python text. Here is the file studentdata.txt.

  2. Do Files Exercise #2 from the online Python text. Here is the file studentdata.txt.

  3. The file movie_data.txt contains information about popular movies from 2015. Specifically, each line of the file gives the release date, title, worldwide gross revenue (in US dollars), and director for a particular movie. These fields are separated by tab characters. Here is a sample line, with tab characters printed \t:

    12 June 2015\tJurassic World\t1670400637\tColin Trevorrow

    This line indicates that Jurassic World was released on June 12, directed by Colin Trevorrow, and grossed $1,670,400,637.

    Write a program that reads such a file and writes a new file called billions.txt containing only the titles of the movies that grossed more than one billion dollars (one movie per line).

  4. Write a function readWords() that accepts the name of a file and returns a list of all the unique words in the file. While reading the words in the file, your function should convert each word to lower case (hint: review Python string methods).

    Your function header should be:

    def readWords(filename):

    For example, suppose the file pat_sat.txt contains the following text:

    PAT SAT Pat sat on hat
    PAT CAT Pat sat on cat

    A call to readWords("pat_sat.txt") should return the following list:

    ['pat', 'sat', 'on', 'hat', 'cat']

    Make sure your function properly opens and closes the file! You may assume that the file contains only alpabetic characters and white space.

Note

Unfortunately, it's difficult to test your solutions to problems 3 and 4 in the code boxes in the online text, because the data files movie_data.txt and pat_sat.txt are not available on in those code boxes. For this homework, and for other assignments involving files, it's better to use Idle on your computer or a lab computer. To access a data file such as movie_data.txt in Python, first open is in your browser, then save it into the same folder where you will your Python program. If you have trouble with this, talk to Prof. Wright.

Submitting your work

Type your solutions in a single Python file. Make sure that Python can run your file without error! Please use comments (lines that begin with a # symbol) to clearly state the problem number for each solution in your file. Save your file and upload it to the HW13 assignment on Moodle.