IT 117: Intermediate Scripting
Homework 5

Due

Sunday, March 2nd at 11:59 PM

What You Need to Do

Setup On Your Machine

Specification

Functions

open_file_read

word_set_create

set_difference

word_set_print

Test Code

Output

Suggestions


  1. Create a file with the hashbang line.
    Copy and paste the headers for each of the three functions into the scrpt.
    The code block for each of these functions should be the single Python statement pass.
    Pass does nothing but it will keep the code from giving syntax errors.
    Run the code.
    You should see nothing.
    If you have errors, fix them.
  2. Copy the definition of open_file_read from hw4.py into your script.
    Copy the test code to the bottom of your script.
    Place a # character before each line of the test script except the first two lines.
    This will stop these statements from running for now.
    This is called "commenting out the code.
    Run the script and fix any errors you find.
  3. Remove the pass statement from word_set_create.
    Create an empty set called word_set.
    Print word_set.
    Run the script and fix any errors you find.
  4. Remove the print statement above.
    Replace it with a for loop that prints each line in the file.
    Run the script and fix any errors you find.
  5. Before the print statement, write an assignment statement that turns line into lowercase using the lower string method.
    Run the script and fix any errors you find.
  6. Remove the print method and replace it with an assignment statement that creates the variable word_list by running the split() method on line.
    Print word_list.
    Run the script and fix any errors you find.
  7. Remove the previous print statement.
    In its place write a for loop that prints each word in word_list.
    Run the script and fix any errors you find.
  8. Replace the print statement with a statement that adds word to word_set.
    Outside both for loops, print word_set.
    Run the script and fix any errors you find.
  9. Remove the final print statement.
    Replace it with a statement that returns word_set.
    Remove the pass statement from set_difference.
    Replace it with a statement that prints the value of the parameters set_1 and set_2.
    Run the script and fix any errors you find.
  10. Remove the print statement. In it's place write an assignment statement that sets the difference between set_1 and set_2 to the variable difference.
    Print difference.
    Run the script and fix any errors you find.
  11. Replace the print statement above with a statement that returns difference.
    Replace the the pass statement in word_set_print with a statement that prints the parameter word_set.
    Remove the # from the test code.
    Run the script and fix any errors you find.
  12. Replace the print statement in word_set_print with a for loop that prints each element of the set.
    Run the script and fix any errors you find.
  13. Change the for loop so it prints the words in alphabetical order.
    Run the script and fix any errors you find.

Output

Your output should look something like this:
Cannot open file xxxxxxx

Words in the first text not found in the second
advanced
battle
field
fought
god
under

Words in the second text not found in the first
battlefield
carried
upon

Copy the file to Unix

Testing on Your Machine

Copy the Script to Unix

Testing the Script on Unix (Optional)

Copyright © 2022 Glenn Hoffman. All rights reserved. May not be reproduced without permission.