Question: Create the file hw5.py. Enter the headers for open_file_read, set_from_file and print_sorted_set. Under each header write the Python statement pass. Run the script. Fix any

Create the file hw5.py. Enter the headers for open_file_read, set_from_file and print_sorted_set. Under each header write the Python statement pass. Run the script. Fix any errors you find.

Copy the function open_file_read from your hw2.py. Copy the test code into the bottom of the file. Comment out all but the first two lines of the test code by placing the hash mark, #, at the beginning of each line. Run the script. You should see nothing. Fix any errors you find.

Remove the pass statement from set_from_file. Write a statement that defines the empty set s. Print s. Remove the comment from the next three lines in the test code, the lines starting with the if statement. Run the script. Fix any errors you find.

Remove the print statement from set_from_file. Write a for loop that prints each line in the file. Run the script. Fix any errors you find.

Remove the print statement after the for loop in set_from_file. Replace it with a statement adds the line, with the linefeed character removed, to the set s. Outside the for loop, print the set s. Run the script. Fix any errors you find.

Remove the print statement from the last line of set_from_file. Replace it with a line that returns the set s. Remove the pass statement from print_sorted_set . Replace it with a statement that prints the parameter s. Uncomment the remaining lines in the test code. Run the script. Fix any errors you find.

Remove the print statement from print_sorted_set. Replace it with a for loop that prints the sorted list of elements in the set. Run the script. Fix any errors you find.

Testing on Your Machine

Open IDLE

Use the Open command in IDLE to open hw5.py

Under the Run menu, select Run Module

Your output should look like this

set 1: 21 elements set 2: 27 elements Union sets 1 & 2: 39 elements Intersection sets 1 & 2: 9 elements Elements in intersection sets 1 & 2 have in is largely learned may remote that the

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!