This program will give you practice with reading from and writing to text files. It will read from a file containing the text to Hamlet's "To Be or Not to Be" speech, encode the text to a second file, and finally decode the encoded text to a third file. The first and third files should match upon the program's completion. A few points to remember while working:
+ Expand Code
import random

KEY = None

def init ():

    """Sets up the global KEY variable"""

    global KEY

    # Begin with list of non-alphanumeric
...

        
Download the following file into the same folder as your program file: original_file.txt
As long as you are using the provided text file as your original input file, then the output should look like it does below. However, if you use different text files for input, then the output will look different each time you run the program -- but the original file and the decoded version should still match.

Program output:

+ Expand Output

Original text lines:
--: To be, or not to be--that is the question:
--: Whether 'tis nobler in the mind to suffer
--: The slings and arrows of outrageous fortune
--: Or to take arms against a sea of troubles
--: And by opposing end them. To die, to sleep--
--: No more--and by a sleep to say we end
--: The heartache, and the thousand natural shocks
--: That flesh is heir to. 'Tis a consummation
...
        
Questions:
  1. How did the process of creating these programs go for you?
  2. What were your main challenges and how did you overcome them?
  3. What did you learn that may be of use as you move along in this class?