CSE 1310-004 (Tiernan)

Lab homework III: Assignments #1 - #3

Due date: Tuesday, Oct. 25, 12pm noon.
    No late labs accepted.

Assignment: There are three programs, Assignments #1, #2, and #3, to write for this lab homework. You will write all of these three programs by yourself. In each assignment, write a Python program to implement the program purpose described for the assignment. You must test and run your program to make sure it works correctly before you turn the program in. For this set of assignments you are required to do input error checking as described in the assignment and as seems reasonable based on the assignment requirements. You will save your Python programs using the naming conventions defined in the lab submission instructions below.

Lab submission instructions:
1) Name each of your Python files as follows : yourlastnameFprogramname.py where "yourlastname" is replaced with your own last name starting with a small letter, the "F" is replaced with the capital letter of your first name, and "programname" is the name of the assignment you are turning in. So if the file I am turning in is Lab III Assignment 2 then I would call my .py file tiernanClab3assnmt2.py . Abbreviations are OK as long as they are easy to understand.

2) I will activate Blackboard for this class and you will submit your assignment through Blackboard. Once I activate Blackboard for the assignments you should be able to see them when you log in to Blackboard. I reserve the right to change how/where you submit labs later in the semester if Blackboard becomes too cumbersome. Check the Blackboard instructions to determine if you should submit .py or .txt files for the assignment.

Grading: This lab homework is worth 100 points and has three programming assignments associated with it.


    Assignment #1: (50 points)
Write a Python program to read in text from a file and process it as described below. The file will contain text with punctuation and the name of the file should be passed in as an argument to the program using argv. Your program should open the file, read the file word by word and create two lists (word list and count list) as follows:

Whenever a word is found in the file, look through the word list to try to find it.

If the word is NOT found in the word list then add that word to the word list as the last element and add a count of 1 to the count list as the last element.

If the word IS found in the word list at location INDEX then increment the count at location INDEX in the count list.

When all the text in the file is read then print the values from the two lists in a table where each line of the table lists a word then its count. Be sure to line up the table columns in printing. An example output from the Gettysburg address might look like:

four 3
score 1
and 14

    Assignment #2: (25 points)
You will create a revised version of the previous assignment as follows: Write a Python program to read in text from a file and process it as described below. The file will contain text with punctuation and the name of the file should be passed in as an argument to the program using argv. Your program should open the file, read the file word by word and create two lists (word list and count list) as follows:

Whenever a word is found in the file, look through the word list to try to find it.

If the word is NOT found in the word list then add that word to the word list in alphabetical order with all the other words. Then add a count of 1 to the count list in the corresponding location. Ex: If the word list is [‘and’, ‘four’, ‘score’ ] and the count list is [2, 1, 1], then to add the word ‘our’ it needs to go between ‘four’ and ‘score’ and it’s count of 1 would be put in as the new 3rd item in the count list.

If the word IS found in the word list at location INDEX then increment the count at location INDEX in the count list.

After a new word is put in the word list, print that list with the count list printed underneath it.

When all the text in the file is read then print the values from the two lists in a table where each line of the table lists a word then its count. Be sure to line up the table columns in printing.

    Assignment #3: (25 points)
You will create a revised version of the assignment #1 as follows: Write a Python program to read in text from a file and process it as described below. The file will contain text with punctuation and the name of the file should be passed in as an argument to the program using argv. Your program should open the file, read the file word by word and create two lists (word list and count list) as follows:

Whenever a word is found in the file, look through the word list to try to find it.

If the word is NOT found in the word list then add that word to the word list as the last element and add a count of 1 to the count list as the last element.

If the word IS found in the word list at location INDEX then increment the count at location INDEX in the count list. THEN compare the updated value in the count list to the value to its left - if the updated value is larger then compare again to the next value on the left until a value is found that is equal to or higher than the updated value or until no more comparisons are possible. Move the updated value to the right of the found value or to the first location if no higher or equal values were found. Use a recursive function to do the comparison tests to find a new index to move the updated value to. There will be two stopping conditions or base cases for the recursive test function. If the updated value is moved then ALSO move the corresponding word to the same location in the word array. Ex:

word list ==> [ 'the', 'four','score', 'and'], count list ==> [2, 1, 1, 1]

Then another 'and' is read which leads to:
word list ==> [ 'the','four','score', 'and'], count list ==> [2, 1, 1, 2]

Now the comparisons start and the two is larger than the value to its right and further right until it is not larger or until no more comparisons can be done. Now we move the 2 to its new location to the right of the other 2 and we move the corresponding word.
word list ==> [ 'the', 'and','four','score'], count list ==> [2, 2, 1, 1]

After a new word is put in the word list or a word is moved, print that list with the count list printed underneath it.

When all the text in the file is read then print the values from the two lists in a table where each line of the table lists a word then its count. Be sure to line up the table columns in printing.


For Lab Homework III, the assignment grading for each assignment will consider the following aspects:
Coding:
    Comments, headers, style, modularity, readability (12% of assignment)
    Program purpose correctly implemented (20%)
    All required components included correctly (10%)
Output:
    Clearly informs user of what is required (16%)
    Performs tasks correctly (27%)
    Provides clear and complete output to user (15%)
Deductions:
    Syntax or logic errors or assignment cannot be run (-100% deduction for assignment)
    Use of library modules/functions if not explicitly listed in assignment description (-35% deduction)
    Use of elements not yet discussed in class UNLESS explicitly listed in assignment (-35% deduction)
        NOTE: if you are not sure whether to use something in Python either leave it out or ask me by e-mail

        NOTE: if you think you cannot finish the lab on time, send me an e-mail and request permission to turn your lab in late. If I allow it, I will send you and the TA a reply and the amount of late penalties by e-mail