Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 2 Review Fall 2003: Encoding and Decoding

Answers? Comments? Questions on Answers? Questions on Comments?

(Back to Fall2003 Midterm Review 2)



def replace(string):
newString1 = string.replace('a','@')
newString2 = newString1.replace('e','#')
newString3 = newString2.replace('i','!')
newString4 = newString3.replace('o','#')
newString5 = newString4.replace('u','^')
newString6 = newString5.replace('r','-')
newString7 = newString6.replace('s','=')
newString8 = newString7.replace('t',':')
print newString8

Yup, this'll work, but you can do it one line. How about the reverse, anyone? Mark Guzdial


def replace(string):
print string.replace("e","#").replace("i","!").replace("a","@").replace("o","#").replace("u","^").replace("r","-").replace("s","=").replace("t",":")

to reverse it you would need to switch the characters in the quotes. like this
("#","e")

what do we do when we reverse it since e and o are changed to the same thing?


Oops! My mistake! Fixed... Mark Guzdial


this may sound dumb but why do you have to put periods after the parentheses? ;P

Because you're using dot notation. Each .replace() returns a string, that you then apply the next one to. Mark Guzdial


Great problem! Why? It's one of the few things that seems easy about this review.



Link to this Page