This lab assignment requires you to write two programs in Python. First, run update21. This will create the cs21/labs/03 directory and copy over any starting-point files for your programs. Next, move into your cs21/labs/03 directory and begin working on the Python programs for this lab. The pwd command helps you verify that you are in the correct sub-directory.
$ update21 $ cd cs21/labs/03 $ pwd /home/your_user_name/cs21/labs/03We will only grade files submitted by handin21 in this directory, so make sure your programs are in this directory!
As you write your first programs, start using good programming practices now:
Write a program that computes the number of points a kicker would earn in fantasy football. Points are awarded according to the following rules:
less than 3 points | mediocre |
3-6 points | typical |
7-10 points | good |
more than 10 points | great |
Here are some sample runs showing how your program should work:
$ python kicker.py How many field goals were made this week? 3 How many yards was field goal number 1? 30 How many yards was field goal number 2? 40 How many yards was field goal number 3? 50 How many extra points were made this week? 2 How many field goals were missed this week? 1 Your kicker earned 13 points and had a great week.
$ python kicker.py How many field goals were made this week? 2 How many yards was field goal number 1? 25 How many yards was field goal number 2? 39 How many extra points were made this week? 1 How many field goals were missed this week? 2 Your kicker earned 5 points and had a typical week.
$ python kicker.py How many field goals were made this week? 0 How many extra points were made this week? 1 How many field goals were missed this week? 0 Your kicker earned 1 point and had a mediocre week.
Let's see an example of how this encryption works by encrypting the phrase "The fat cat." The first thing our encryption algorithm does is strip out everything that is not a character. This gives us the string "Thefatcat". Now we break up the string into rows and columns. For this example we are choosing the column size of three. When we do this our string now looks like:
The fat catThe encrypted text is the phrase you get reading reading down from the columns:
Tfc haa ettIn this example, "Tfc" is the first column, "haa" is the second column, and "ett" is the third column. Let's look at another with the phrase "meet me in sharples at six o'clock" and a column size of 5. First we remove anything that is not a letter from our string to get "meetmeinsharplesatsixoclock". Then we block off the text in groups of 5.
meetm einsh arple satsi xoclo ck
In this case, the string doesn't fill out the block completely, so we need to pad out the string with extra characters. For this assignment, we will pad the string out with the lowercase 'x's. This give us:
meetm einsh arple satsi xoclo ckxxxNow we read down the columns to get our encrypted string: "measxceiraokenptcxtslslxmheiox" (column 1: measxc, column 2: eiraok column 3: enptcx, column 4: tslslx, and column 5: mheiox). To make the encrypted string easier to read, we'll always display our message in groups of 5 characters (this is the traditional way to print out encrypted text messages).
measx ceira okenp tcxts lslxm heiox
To complete this assignment, your program should do the following:
Here are some examples of the program being run:
$ python cipher.py Enter the message to encrypt: meet me in sharples at six o'clock. How many columns to use in encryption? 5 Your encrypted message is: measx ceira okenp tcxts lslxm heiox
$ python cipher.py Enter the message to encrypt: I think therefore I am. How many columns to use in encryption? 3 Your encrypted message is: Iitro Itnhe rahke fem
$ python cipher.py Enter the message to encrypt: Live life to the fullest. How many columns to use in encryption? 5 Your encrypted message is: Litli fhlve eeetf slout
$ python cipher.py Enter the message to encrypt: Don't Panic How many columns to use in encryption? 3 Your encrypted message is: DtnoP inac
$ python cipher.py Enter the message to encrypt: So long, and thanks for all the fish. How many columns to use in encryption? 6 Your encrypted message is: Sanaf onkli ldsls otfth nhohx garex
$ python cipher.py Enter the message to encrypt: Time is an illusion. Lunchtime doubly so. How many columns to use in encryption? 4 Your encrypted message is: TiisL heboi sliut dlxma lonio yxenu ncmus xHints for doing this assignment:
Write a program, decrypt.py to decrypt the output from the previous program. The user will have to enter the encrypted string, and the number of columns used to encrypt the phrase.
Remember you may run handin21 as many times as you like. Each time you run it new versions of your files will be submitted. Running handin21 after you finish a program, after any major changes are made, and at the end of the day (before you log out) is a good habit to get into.