You worked late into the night on an assignment and didn’t realize that you wrote a huge section of your term paper with your fingers on the wrong home keys. Where you meant to type: “This is an unruly mob.” You actually typed: “Ty8s 8s ah 7hr7o6 j9b.” Basically you swapped: 6 for Y, 7 for U, 8 for I, 9 for O, 0 for P, U for J, I for K, O for L, H for N, and J for M. (Those were the only keystrokes you got wrong—you caught yourself before you got much further.) You also never touched the shift key, so it’s only lowercase letters that you care about. Knowing Python as you do, you decide to write a quick program to fix your text. Write a function fixItUp that takes a string as input and returns a string with the characters put the way that they ought to have been.

What will be an ideal response?


Note: The easiest way to accomplish this answer is to make use of the “replace” method. However, an answer needs to be aware of the order that the replaces occur in. For example, if an answer swaps out I and 8 and then K and I the end result would be some letters that should be I’s becoming K’s. One way to avoid this is to reverse the list of swapped characters and replace in that order, as below. Additionally, the question does not mention it, but in the example it shows that H also got swapped for Y.

```
def replaceCharacters(string):
newString = string.replace("j", "m")
newString = newString.replace("h", "n")
newString = newString.replace("y", "h")
newString = newString.replace("o", "l")
newString = newString.replace("i", "k")
newString = newString.replace("u", "j")
newString = newString.replace("0", "p")
newString = newString.replace("9", "o")
newString = newString.replace("8", "i")
newString = newString.replace("7", "u")
newString = newString.replace("6", "y")
return newString
```

Computer Science & Information Technology

You might also like to view...

A web page consists of ____ sections.

A. two B. three C. four D. six

Computer Science & Information Technology

The ________ pane tracks all objects, shapes, pictures, and placeholders that display on a slide

A) Clipboard B) Format Shape C) Slide D) Selection

Computer Science & Information Technology

Which panels do you use to format text?

What will be an ideal response?

Computer Science & Information Technology

What environmental conditions increase the risk of ESD?

What will be an ideal response?

Computer Science & Information Technology