File IO
File IO
CSC1015F Assignment 10
File Input and Output
Assignment Instructions
This assignment involves constructing Python programs that perform file input and output.
Furthermore, your solutions to this assignment will be evaluated for correctness and for the following
qualities:
• Documentation
o Use of comments at the top of your code to identify program purpose, author and
date.
o Use of comments within your code to explain each non-obvious functional unit of
code.
• General style/readability
o The use of meaningful names for variables and functions.
• Algorithmic qualities
o Efficiency, simplicity
These criteria will be manually assessed by a tutor and commented upon. Up to 10 marks will be
deducted for deficiencies.
Given two words, each is an anagram of the other if they contain the same letters in the same
quantities. For example, 'green' and 'genre'. Note that the words are not case sensitive.
Sample IO (The input from the user is shown in bold font – do not program this):
***** Anagram Finder *****
Enter a word: triangle
['alerting', 'altering', 'integral']
Sample IO (The input from the user is shown in bold font – do not program this):
***** Anagram Finder *****
Enter a word: Orange
['onager']
Sample IO (The input from the user is shown in bold font – do not program this):
***** Anagram Finder *****
Enter a word: back
Sorry, anagrams of 'back' could not be found.
Page 1 of 4
Sample IO (The input from the user is shown in bold font – do not program this):
***** Anagram Finder *****
Sorry, could not find file 'EnglishWords.txt'.
A lexicon (words file) has been provided on the Vula assignment page (‘EnglishWords.txt’).
NOTE: This file begins with a copyright notice that should not be removed. Your program must skip
this notice by reading lines until it encounters one consisting of the word "START".
NOTE: The last example of program behaviour shows what the program should do if it does not find
the words file.
• Given the name of a Python program as input, ‘tracer.py’ will insert a trace statement at
the beginning of each function definition.
• Given the name of a program that already contains trace statements, ‘tracer.py’ will
remove them.
Page 2 of 4
Here’s a sample of its behaviour:
Enter a sentence: how now brown cow
woc nworb won woh
woc nworb won wohwoc nworb won woh
Given the file name‘rfunction.py’ as input, ‘tracer.py’ will produce the following
transformation:
"""DEBUG"""
# Reverse a string, Hussein Suleman, 18 march 2015.
The program inserts the docstring """DEBUG""" at the start of the file. After the signature line of
each function it inserts the same docstring followed by a semicolon, followed by a statement that
prints the name of the function.
Running the transformed ‘rfunction.py’ (with the same input as before) produces this
transcript:
main
Enter a sentence: how now brown cow
reverse_string
woc nworb won woh
reverse_string
woc nworb won wohwoc nworb won woh
The transcript now shows what function was executed at which point.
Given ‘rfunction.py’ as input for a second time, ‘trace.py’ will return the text to its
original form.
Page 3 of 4
To complete the example, here is the expected user interaction for each execution of ‘trace.py’:
***** Program Trace Utility *****
Enter the name of the program file: rfunction.py
Inserting...Done
Sample IO (The input from the user is shown in bold font – do not program this):
***** Anagram Set Search *****
Enter word length:
12
Searching...
Enter file name:
twelve.txt
Writing results...
Submission
Create and submit a Zip file called ‘ABCXYZ123.zip’ (where ABCXYZ123 is YOUR student number)
containing anagramsearch.py, tracer.py, and anagramsets.py.
Page 4 of 4