I am making a program that takes a sentence and garbles it, until run through a “degarbler”
Theres probably a better way to do this, but I would appreciate it if everyone would show me how to fix what I am doing wrong
def sencoder (sentence):
sentence = sentence.replace ("a","h")
sentence = sentence.replace ("s","j")
sentence = sentence.replace ("d","k")
sentence = sentence.replace ("f","l")
sentence = sentence.replace ("b","g")
sentence = sentence.replace ("z","t")
sentence = sentence.replace ("q","y")
sentence = sentence.replace ("w","u")
sentence = sentence.replace ("e","i")
sentence = sentence.replace ("r","o")
sentence = sentence.replace ("x","p")
sentence = sentence.replace ("c","b")
sentence = sentence.replace ("v","n")
sentence = sentence.replace ("m","m")
print sentence
def decoder (sentence):
sentence = sentence.replace ("h","a")
sentence = sentence.replace ("j","s")
sentence = sentence.replace ("k","d")
sentence = sentence.replace ("l","f")
sentence = sentence.replace ("g","b")
sentence = sentence.replace ("t","z")
sentence = sentence.replace ("y","q")
sentence = sentence.replace ("u","w")
sentence = sentence.replace ("i","e")
sentence = sentence.replace ("o","r")
sentence = sentence.replace ("p","x")
sentence = sentence.replace ("b","c")
sentence = sentence.replace ("n","v")
sentence = sentence.replace ("m","m")
print sentence
sentence = ""
choice = raw_input ("Do you want to decode or encode: ").lower()
while sentence != "quit":
sentence = raw_input("Enter the code: ")
if choice == "encode":
decoder(sentence)
elif choice == "decode":
sencoder(sentence)
else:
print "Please make a valid decision"
help
Here is a hint: Use the
translatemethod instead.