Project 6: Word Train

  < Previous  Next >

Assignment id: project6
Required Files: project6.py, rubric6.txt

Due Date

See the calendar for due date.

Objectives:

Description:

For this project, we get to store words in a list (with each word as it's own element). Furthermore, you get to perform the following operations on the list:
Format: 	              Description:
Insert\t<index>\t<word>       Add word in the list at index (so that all the elements
                              with indices from index until the end of the list, have
                              an index one greater than what they previously had)
Append\t<word>                Add word at the end of the list
Remove\t<word>                Remove the first occurrence of word from the list (so
                              that all the elements with indices from index until the
                              end of the list, have an index one less than what they
                              previously had).  If word is not found, display a
                              message and continue.
Delete\t<index>               Remove the element at index from the list (so that all
                              the elements with indices from index until the end of
                              the list, have an index one less than what they
                              previously had).  If index is too large, display a
                              message and continue.
Print                         Display each element in the list, separated by a space
Display\t<index>	      Display the element at index.  If index is too large,
                              display a message and continue.
Substitute\t<word1>\t<word2>  Replace the first occurrence of word1 with word2.  If word1
                              is not found, display a message and continue

Examples

Example input files: The following are examples of correct execution (with the text in bold being the input from the user):
project6-testA.tab:
append	Hello
append	everyone
print
substitute	everyone	world
print
insert	1	happy
print
remove	happy
print
insert	1	bright
insert	1	beautiful
print
delete	2
print
Output:
Please enter the word commands file name: project6-testA.tab
You entered project6-testA.tab

Hello everyone 
Hello world 
Hello happy world 
Hello world 
Hello beautiful bright world 
Hello beautiful world
project6-testB.tab:
remove	does_not_exist
append	forty-two
insert	0	answer
insert	1	is
insert	0	The
print
display	99
display	3
delete	99
print
substitute	oil	applesauce
print
Output:
Please enter the word commands file name: project6-testB.tab
You entered project6-testB.tab

Can not remove "does_not_exist", it's not in the list!
The answer is forty-two 
Can not display index 99, there's only 4 words!
forty-two
Can not delete index 99, there's only 4 words!
The answer is forty-two 
Can not substitute "applesauce" for "oil", because "oil" is not in the list!
The answer is forty-two

Submission

Submit your python script and rubric using the handin program. For handin, for this project, type the following in a terminal window exactly as it appears:
handin  project6  project6.py  rubric6.txt
To verify your submission, type the following in a terminal window:
handin  project6

Rubric:

Points       Item
----------   --------------------------------------------------------------
_____ / 20   Meaniful comments (at the beginning of the file, before each function, etc.)
_____ /  8   Properly handles input file (e.g., handles IO exceptions, close the file)
_____ / 10   Uses a list data structure to store the words
_____ / 40   Accurately executes the commands in the input file 
_____ /  2   Completed rubric (estimates for each line including hours spent)

_____ / 80   Total


_____  Approximate number of hours spent

Helps

  1. Before writing any code, write the comments first!
  2. Write the code iteratively. For example, write the code to get the input file name. Then, execute the code to verify that it works. Then, write the code to try to open the file. Then, execute the code to verify that it works. Then, write the code to parse just the lines with the print command. Then, you guessed it, execute the code to verify that it works. Then, write the code for another command. ...

Notes

  1. Optionally, you can replace typing from the keyboard with the contents of a file. For example, try on ranger:
    echo "project6-testA.tab" | python3  project6.py
    If you want to match my output exactly, then run the following on ranger:
    echo "project6-testA.tab" | python3  project6.py  > outA.txt
    diff /nfshome/hcarroll/public_html/1170/private/projects/project6-answerKeyA.txt  outA.txt
    If the two files match exactly (which is what you want) then there should be NO output from diff. If diff shows one or more differences, fix them and run it again. To get side-by-side output (with the answer key on the left and your output on the right), replace the last line with:
    diff  --side-by-side  /nfshome/hcarroll/public_html/1170/private/projects/project6-answerKeyA.txt  outA.txt
    For details about interpreting the output of diff, see the Using diff section on the Misc. webpage.