CSC111 Homework 9

From CSclasswiki
Jump to: navigation, search

--Thiebaut 02:31, 7 April 2009 (UTC)




Due Date

The two programs for this assignment are due before midnight, the evening of Monday April 13th.

Problem #1 (7 points)

Both programs should be done with Python in your Linux account.

Get a copy of a python program that will be the start of your program.

    [111b-xx@beowulf ~]$  getcopy hw9start.py

Then copy it to a new file:

    [111b-xx@beowulf ~]$  cp hw9start.py  hw9.py

cp stands for copy and makes a new copy of your program called hw9.py in your Linux account.

To verify that you have these two files in your account, get a listing of your files:

    [111b-xx@beowulf ~]$   ls

(that's ell ess) where ls stands for list files.

The program contains only a string of character that is 80 lines long:

# -*- coding: utf-8 -*-
# hw9.py
# 
# start section
#
movies = """1.	9.1	The Shawshank Redemption (1994)	417,427
2.	9.1	The Godfather (1972)	347,404
3.	9.0	The Godfather: Part II (1974)	201,520
4.	8.9	Buono, il brutto, il cattivo., Il (1966)	122,618
5.	8.9	Pulp Fiction (1994)	342,899
6.	8.9	The Dark Knight (2008)	359,778
7.	8.8	Schindler's List (1993)	227,442
8.	8.8	One Flew Over the Cuckoo's Nest (1975)	174,583

...

75.	8.4	All About Eve (1950)	29,532
76.	8.4	Modern Times (1936)	28,481
77.	8.3	Singin' in the Rain (1952)	46,328
78.	8.3	Gran Torino (2008)	53,632
79.	8.3	Der Untergang (2004)	64,126
80.	8.3	Metropolis (1927)	31,952
"""

(The whole program is available here.)

Start editing your program:

  [111b-xx@beowulf ~]$   emacs hw9.py

Warning!

Note that the lines contain spaces and tabs. A tab may look like several spaces, but it is only one character. A tab character in python is '\t'. So if you want to search for a tab in a string called line, you would write

   line.find( '\t' )

Assignment

Your assignment is to build up this program so that it

  1. processes the list of movies, and then
  2. prints the list of all the movies that came out in 2000 or later, sorted by order of their score, best movie first. The list of movies printed should show one movie per line, the name of the movie first, followed by the score, and the year. Make sure you print a header before the list to identify it.
  3. The program will also print the list of the ten oldest movies, sorted alphabetically. The list will be printed after the previous list, with a header indicating the beginning of a new list. Here again I would like to see the name of the movie first, followed by the score, followed by the year.

Requirements

  • Documentation: Your program should have a header explaining what the program does, what it prints, what its limitations are, if any. By the way, the first line of the program should remain "# -*- coding: utf-8 -*-". It tells the python interpreter that some of the strings contain foreign characters, like in the French movie Leon.
  • Each function should have a header indicating what it does, what it receives as parameters, and what it returns, if anything.
  • Your program should compute all the quantities it requires. Don't use constants for indexes in the string. Make your program compute the indexes.
  • Remember: a program that runs without crashing is worth more points than one that has lots of code but does not run correctly!

Submission

Once your program is done, you submit it as followed:

   [111b-xx@beowulf ~]$   submit hw9 hw9.py

The submit command will automatically store your program in the folder hw9 in a drop box on the Linux server and will automatically add your 111b-xx account name to the name of the program. So, please, make sure your program is called hw9.py, and nothing else!

Problem #2 (3 points)

The purpose of this problem is to extend the features of the program you wrote for Problem #1 and make it more robust.

For this assignment you will submit two programs, hw9.py, which implements the answers for Problem #1, and hw9b.py, which is an improved version of hw9.py, more robust, and implementing the requirements explained below. The two programs will be tested separately.

Make a copy of your program under a new name:

   [111b-xx@beowulf ~]$  cp hw9.py  hw9b.py

And edit it with emacs:

   [111b-xx@beowulf ~]$ emacs hw9b.py


Add the following lines at the end of the movies string:

	8.3	Some Like It Hot (1959)	56,171
81.	8.3	Rebecca (1940)	29,139
83.	8.3	Amadeus  [1984] 81 316         
84.    	8.3	  The Prestige               (2006)	       156,204
85.	8.3	The Elephant Man (1980)	47,003
86.	8.3	Sin City (2005)	210,757

The new string with all the movies is available here.

and modify the program so that it will skip the lines that are not properly formed without crashing. We assume that a line that is not correctly formed either does not contain the correct information, as in Some Like It Hot, which is missing the first ranking number, or do not have years in parentheses. An example of this is Amadeous where brackets are used instead of parentheses.

Your program should simply skip lines that cannot be properly processed, i.e. Some Like It Hot, and Amadeous. But it should still attempt to read all the movie. The 84th, 85th, and 86th entries are all three valid, and your program should process them.

Requirements

  • Make sure you document well any new code you add
  • Make sure the program does not stop reading the movie lines when it finds a problem, but simply skips the line with the problem in it. You will need to learn more about for-loops, break and continue statements (see this short tutorial for example).
  • The output of your program should include the new movies added to the list, if the lines that contain them is valid, and if they match the various requirements.

Submission

Once your second program is ready, submit it as follows:

   [111b-xx@beowulf ~]$   submit hw9 hw9b.py

To verify that your program has been correctly submitted, you can try submitting a second time. If you are asked whether you want to replace the copy that already exists, then that means the system copied your file correctly the first time. You can submit a program as many times as you want. But remember that the date and time of the last submission is what is recorded by the system. The grading software under Linux will flag all the programs submitted after the deadline, so make sure you submit your programs on time!


Study the solutions for Lab 9 and for the exercises we did in class for inspiration. Read them carefully before and during your work on this assignment.