|Welcome to CS1315. Click on the python to add comments.|
|This page removed for FERPA compliance|
Midterm Exam 2 Review Spring 2006: Encoding and Decoding
letter = "Mr. Mark Guzdial REMOVEDs the pleasure of your company at..."
|This would ALMOST work, you are calling the wrong variable somewhere. HOWEVER, read the question again. It needs to accept the string to manipulate as input. -Student2042 |
except add some spaces under def!!!!
| This is not what the question is asking for, its asking for a code that takes in any string, and replaces the set consonants displayed... Keep working on this :)... and for future reference, post the code with <code></code> tags around it to preserve formatting Student3381|
does anyone know the answer to question (b)????
|If you post something, we will gladly tell you if it is incorrect. Try working through it. -Student2042|
should the answer for part 'a' somehow be kept and automatically put into the program for part 'b', or do you just want to see us reverse the order of replacement (i.e., string.replace('-','r').replace('s','=').replace('t',':'))?
It's cheap, but it works.
|And what happens when you have hyphens and equal signs in the string? -Student1680|
REMOVEDw about this one?
Is this correct for part b?
Is this correct for part c?
string = string.replace("a","####")
string = string.replace("b","a")
string = string.replace("####","b")
|And what happens when there's a #### in the string you're modifying? -Student1680|
i think i am making this REMOVED complicated than it actually is but this is my code:
letter = string
new = letter.replace('r','-').replace('s','=').replace('t',':')
when i try to run replace(Mr. Mark Guzdial REMOVEDs the pleasure of your company at) in the command area i get that its not legal but its not the code thats not legal its the command i just tried to run – i am so confused
i checked my code i actually do have a colon @ the end of line one i just left it off here – any other idea??
Am I anywhere close for C on this:
for i in a:
loc = string.find(i)
while loc <> -1:
for i in b:
while loc <> -1:
|The returns will both do exactly that: return control to the function that called encodeDecode. So the code after them (actually the code after the first return) will never get executed. For that reason, a return should generally be the very last command in a function or the last command in an if block. Colin Potts|
Link to this Page