Question: Deliverables There is one deliverable for this assignment hw5.py Make sure the script obeys all the rules in Homework Script Rules Specification The script must

Deliverables

There is one deliverable for this assignment

  • hw5.py

Make sure the script obeys all the rules in Homework Script Rules

Specification

The script must have 5 functions

  • open_file_read
  • word_set_from_file
  • ordered_word_set_print
  • word_count
  • set_difference

open_file_read

This function must have the following header:

def open_file_read(filename):

It must try to create a file object for reading on the file whose name is given by the parameter filename.

If it is succesful in creating the file object it should return the object.

If it is cannot create the object it should print an error message and return None.

word_set_from_file

This function must have the following header:

def word_set_from_file(filename):

It must read in a file and create a set of the words in that file.

All words added to the set must be lowercase.

It must return that set.

ordered_word_set_print

This function must have the following header:

def ordered_word_set_print(set):

It must print the elements of the set given as a parameter in alphabetical order.

word_count

This function must have the following header:

def word_count(filename):

It must read in a file and count the words in the file.

It must return the word count.

set_difference

This function must have the following header:

def set_difference(set_1, set_2):

It must return the difference between the two sets given to it as parameters

Script for this assignment

Open an a text editor and create the file hw5.py.

You can use the editor built into IDLE or a program like Sublime.

Test Code

Your hw5.py file must contain the following test code at the bottom of the file:

filename_1 = "gettysburg.txt" set_1 = word_set_from_file(filename_1) ordered_word_set_print(set_1) word_count(filename_1) filename_2 = "gettysburg_hay.txt" set_2 = word_set_from_file(filename_2) print() print("Words in " + filename_1 + ":" + str(word_count(filename_1))) print("Words in " + filename_2 + ":" + str(word_count(filename_2))) print() print("Words in " + filename_1 + " not in " + filename_2) ordered_word_set_print(set_difference(set_1, set_2)) print() print("Words in " + filename_2 + " not in " + filename_1) ordered_word_set_print(set_difference(set_2, set_1))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!