CSSE 120 -- Intro. to Software Development

Homework 5

A great place and time to do these exercises are the CSSE lab F-217 during student assistant hours, since you can get immediate help from the lab assistant.

  1. Do these instructions for installing PyDev and Eclipse.
  2. (30 pts) Decoding messages: the accumulator loop pattern, chr and ord. Suppose you are a security agent who encrypts messages that you send to other agents.  Of course, the receiving agents need to be able to decode the encoded messages they receive from you.

    Assuming that both you and the agents receiving your messages share a common key that you use to encode and decode messages, write a decode module in a file named decode.py that:

    1. Prompts the user for the list of numbers that encodes the message.
    2. Prompts the user for a key (an integer between -30 and 100).
    3. Reverses the calculation of this encode module and prints the string that results.

    Here is a sample run, assuming that the encoding was done with key = 42. Note the format of the input and output, where red shows what the user types.

    Enter the list of numbers that encodes the message: [126, 153, 154, 74, 157, 143, 141, 156, 143, 158]
    Enter the key (an integer between -30 and 100): 42
    The decoded message is: Top secret
    

  3. (15 pts) Loops and string formatting: Storing information in files is an important exercise for engineers and scientists running experiments that generate a large quantity of useful data.  The stored data can later be analyzed, categorized, and manipulated to allow engineers/scientists to draw useful conclusions.  In this problem, you will write the data to the screen; in the next problem, you will actually write it to a file.

    Often, the generated data is formatted so that another program can automate the process of analyzing, categorizing, and manipulating the data. In this problem you are to write a program called functionToConsole.py that implements the following design:

    Here is a sample run, where red shows what the user types.

    How many data points do you want? 20
     0  300.000
     1  296.962
     2  287.939
     3  273.205
     4  253.209
     5  228.558
     6  200.000
     7  168.404
     8  134.730
     9  100.000
    10   65.270
    11   31.596
    12    0.000
    13  -28.558
    14  -53.209
    15  -73.205
    16  -87.939
    17  -96.962
    18 -100.000
    19  -96.962
    

    Submit your Python source file functionToConsole.py to the FunctionToConsole drop box in the Homework 5 folder on ANGEL.

  4. (15 points) Repeat the previous problem, but this time name your program functionToFile and have the program write the output to a file named dataPoints.txt instead of to the screen.
  5. (15 points) Repeat problem 3 above, but this time:

    Here are two sample run, where red shows what the user types. As the examples suggest, your program should work for ANY single-valued function of n.

     Sample run 1: 
    What function do you want to use? 4.815162342**n + 42
    How many data points do you want? 10
     0   43.000
     1   46.815
     2   65.186
     3  153.643
     4  579.581
     5 2630.539
     6 12506.234
     7 60059.311
     8 289035.098
     9 1391590.683
    
     Sample run 2: 
    What function do you want to use? 4 + 8*n + 15*n**2 +  16*n**3 + 23*n**4 + 42*n**5
    How many data points do you want? 6
     0    4.000
     1  108.000
     2 1920.000
     3 12664.000
     4 50196.000
     5 148044.000
     

    This problem is easy once you see the “trick” to it; don't spend more than 15 minutes on this problem without seeking help! The key ideas for solving this problem are:

    To repeat: if you don't see how to do this problem, ask for help! (Bring your questions to class, you'll have time in class to complete the problem then if you need to.)

    Submit your Python source file anyFunctionToConsole.py to the AnyFunctionToConsole drop box in the Homework 5 folder on ANGEL.

  6. Web links, bacon, eggs, and spam: The spam.py module that you will use to test your Subclipse installation is a reference to the Penguin sketch. We hope you enjoy this four minute cultural experience!