< Back

Test 3

Create the following directories for storing your answers to today's test. Make sure all of the files you create are stored within this directory.

$ cd ~/cs120/
$ mkdir test3
$ cd test3

You are only allowed to access this course webpage and the Python and Turtle documentation webpages. You are not allowed to access any other websites. You are not allowed to access files from your directory, or files from any other user's directories. Failure to abide by these rules is a violation of Academic Integrity, and will be treated as such.


Question 11

In a file called question_11.py, write a function called higher_lower(a_number). This function should generate a number in the range \([0, 100)\). It should ask the user to input a guess of the number. If the user inputs the correct number, then the game is over. Otherwise, it should report to the user if their guess is higher or lower than the generated number, and have them guess again.

Sample Run

Assume the randomly generated number is 27.

  Guess a number: 25
  You are lower
  Guess a number: 29
  You are higher
  Guess a number: 27
  Correct!

(10 points)


Question 12

Write a function called split_string(a_string) in a file called question_12.py, which takes a single string as a parameter. Your function should print every word from the string parameter independently. Assume all words in the string are separated by spaces.

Example Output

>>> split_string("This is a super fun and useful class")
This
is
a
super
fun
and
useful
class

(10 points)


Bonus

Transposition Cipher

In a transposition cipher, instead of shifting each character of the plaintext string through the alphabet, you shift the position of the plaintext character in the cipher text.

For example, the string "hello" could be encoded using the transposition cipher into: "lheol". The key for this would be "1 2 0 4 3". This key means that the character at position 0 goes to position 1 in the cipher text, the character at position 1 goes to position 2 in the cipher text, and so on.

In a file called question_bonus.py, write a function called encode_transposition(plaintext, key). This function takes two strings. The key is of the form specified above. Your function should return a string, which is the encoded version of the plaintext using the key.

(8 points)


Submission

When you have finished, create a tar file of your test3 directory. To create a tar file, execute the following commands:

cd ~/cs120
tar czvf test3.tgz test3/

To submit your activity, go to inquire.roanoke.edu. You should see an available assignment called Test #3.