Date

Due: Monday, October 17, 11:00 AM

Write a program called scrambled.py that will take a paragraph of text and return the same paragraph, but with each word's letters scrambled according to the algorithm described below.

Read the following paragraph as quickly as you can and see if you have any problems:

Ardcnciog to rreasech at an Eniglsh utnivriesy, it deos not mtaetr in waht odrer the lertets in a word are, the only iaomnrptt tnihg is taht the frsit and last leettr is in the rihgt pcale. The rest can be a ttaol mses and you can stlil read it wthuoit mcuh issue. Tihs is becsaue we do not raed erevy lteetr by istlef but the wrod as a wlohe.

Now, what's important to note is that while the "research" here isn't terribly solid, the result is still quite interesting. For small-to-medium length words, it does seem to hold true that it is not hard to read a scrambled word with the first and last letters still in the correct location.

You are going to write a program that will take an unscrambled paragraph and then scramble each word like we did above.

Your program should do the following:

  1. Prompt the user for the text to scramble.
  2. Prompt the user for a seed for the random number generator (just like with election.py).
  3. Take each word in that sentence and scramble it using a function you write called scramble_word(word) that takes one word as the parameter and returns that word scrambled.
  4. Put the text back together and print it.

You MUST implement this program by writing a function called scramble_word(word). We will test your code for its presence. The user input and looping to call the function on each word can be done however you like.

You have to follow certain rules when scrambling a word:

  1. The first letter must stay in the first position.
  2. The last letter must stay in the last position.
  3. Punctuation at the end of a word (such as a comma or exclamation point), must also still be at the end of the word, in addition to the last letter of the word also staying in place.
  4. Punctuation in the middle of a word (such as an apostrophe) should move around as if it were any other letter (trust us - this makes the code easier to write).
  5. Note that any word of 3 characters or less does not need to be scrambled.
  6. It is okay if a word is scrambled and happens to come back as the original word.

Here are some hints as to how to do this:

  1. You can convert a string to a list with the command list(str), where str in this instance is the string to convert.
  2. You can add import string at the top of your code to get access to a list called string.punctuation which lets you test to see if a character is a punctuation mark. For example "!" in string.punctuation would result in True.
  3. You can add import random at the top of your code to get access to random.shuffle() which will randomize the items in a list with the line random.shuffle(my_list_to_randomize).
  4. The command "".join(my_list) will convert a list to a str.

An example run would look like this:

Enter your text: We love computer science!
Enter a seed (0 for random): 4
Your scrambled sentence is: We lvoe cetmuopr seincce!

HINT: If you run this and get We lvoe cumeoptr scenice!, then you probably are not casting the input for the seed to an int before using it!

Another example:

Enter your text: Commas, while tough, are doable.
Enter a seed (0 for random): 5
Your scrambled sentence is: Comams, wihle tgouh, are dabloe.

Another example:

Enter your text: Even multiple periods.... can be done!
Enter a seed (0 for random): 4
Your scrambled sentence is: Eevn mlpliute pirodes.... can be done!

Submission: Please submit one .py file named scrambled.py to the POTD submission system at https://archimedes.cs.virginia.edu/cs1110/