Lab homework V: Assignment #1

Design document Due date: Thursday, Dec. 8 12pm noon. Design document must be turned in for lab to be graded. See description below.

Lab Due date: Thursday, Dec. 15 12pm noon.
    Absolutely NO late labs accepted. See notes at end for extra credit for early submission

Assignment: There is one program, Assignment #1, to write for this lab homework. You will write all of this program by yourself. In the 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 V Assignment 1 then I would call my .py file tiernanClab5assnmt1.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 one programming assignment associated with it. There is a required design document due one week before the lab. This design document must be turned in in order for the lab to be graded when it is turned in later.


    Assignment #1: (100 points)
Write a Python program to read in text from a file, process it, and write out the results to a second file. The input file will contain text with punctuation. Your program will find the words, record them and count them. The punctuation must be removed and all capitalization standardized. This program will act just like Lab IV Assignment #2 for the words. However for this lab, instead of using a dictionary, you must define a Python class, give it appropriate attributes and define methods for the class.

 

You will also practice planned development by turning in a design document for your assignment by Thursday, Dec. 8 noon. This design can be bullet points, verbal descriptions or pictures. It can be hand-written, typed, drawn, etc. No specific format is required. It should fit on one side of an 8.5" x 11" piece of paper. The design document must contain the name and brief descriptions (1 sentence) of all functions and class methods you plan to write and when each function/method would be used. It is OK if the overall design changes some once you are further into the development process.

 

For Lab V, specifically you must do the following:

 

1) Instead of creating a Python dictionary to store the word information, you must create a Python class. This class must contain one attribute (member of the class) for each letter of the alphabet and these attributes should be created as needed. The value of the attribute will be the list of sublists just like you used in Lab IV Assignment #2. As an example, if you define your class and then create an object mywords of that class, then to put your word information into your object you would assign attributes like mywords.b = [["banana", 2], ["biscuit",1]] or mywords.m = [["milk", 1]] . (Remember that attributes for classes are created like variables. Once you make an assignment to that attribute then it exists like the b and m attributes in the example.) The sublists and counts should be created while you are processing the text just like in Lab IV. Do not read all the words into a dictionary and then create the object from that. Build the object attributes just like you built the dictionary entries before.

 

2) The python class you create must also contain some methods that you will need to define. The minimum required methods are:

A. a printattrs method that we will go over in class and I will include as a function at the bottom of this assignment. See the Notes section.

B. a file writing method that gets data from the class attributes labeled with letters and write that data to a text file in the SAME FORMAT as Lab IV. This means that you will need to use the letter strings as the attributes in the object that you write to the file.

C, a method to search through every value of every letter attribute of your object to look for a given word. For example if you called this method searchword then you would call mywords.searchword("biscuit") or mywords.searchword("butter"). This function should return True or False.

 

To accomplish these tasks you will need to explore the build-in functions for Python classes, especially the functions about attributes such as getattr or hasattr.

 

After you have processed all the words and stored them in the object, then you should print all the letter attributes and their values using the printattr method and you should write all the object attribute data to the file as described above. Your program should then ask the user if they wish to search for a word in the object and if so, let the user enter a word and use your searchword method to find it. Let the user search for words repeatedly until they indicate they are done.

 

Print a Thank you message for the user when the program ends.

 


For Lab Homework V, the assignment grading for each assignment will consider the following aspects:
Coding:
    Comments, headers, style, modularity, readability (10% of assignment)
    Program purpose correctly implemented (12%)
    All required components included correctly (22%)
Output:
    Clearly informs user of what is required (14%)
    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

Early submission extra credit:

For the final lab, no late labs will be accepted. However, the following extra credit will apply:

Programs turned in by 11:59pm on Monday, Dec. 12 will receive 20 points extra credit

Programs turned in by 11:59pm on Tuesday, Dec. 13 will receive 14 points extra credit – This is the day of the CSE 1310 final exam

Programs turned in by 11:59pm on Wednesday, Dec. 14 will receive 8 points extra credit

Lab is due at noon, Thursday, Dec. 15

ABSOLUTELY NO LATE LABS WILL BE ACCEPTED FOR LAB V

Partial labs can be turned in for partial credit. Labs that are turned in must work CORRECTLY and WITHOUT ERRORS even if they only do part of the lab assignment, i.e. the part that is turned in must be done correctly.

 

NOTE: If you have trouble with Blackboard, send me an e-mail ASAP and attach your lab assignment to that e-mail.

 

Notes:

This is a function for printattr that will check all the letters of the alphabet to see which letters are attributes in your class and then print the values

associated with any letter attributes in your class. You need to turn it into a method and put it in your class.

 

def printattr(wordobj):

# NOTE: you need to finish the alphabet list and include all the letters

alphabet = ['a','b','c','d','e','f','g','h']

for ltr in alphabet:

if hasattr(wordobj,ltr):

print "For attribute",ltr,"the value is",

print getattr(wordobj,ltr)