-2

What I want to do is make a test encoder but I can't manage to turn the user's input into individual variables that have the user's individual text letters in them. How do I do it? I have tried many different answers on this site but none of them work. Here's my code:

encode = {
  "!" : "!","?" : "?","." : ".","," : ","," " : " ","A" : "7","B" : "8",
  "C" : "9","D" : "4","E" : "5","F" : "6","G" : "1","H" : "2","I" : "3",
  "J" : "÷","K" : "*","L" : "-","M" : "+","N" : "(7)","O" : "(8)", "P" : "(9)",
  "Q" : "(4)","R" : "(5)","S" : "(6)","T" : "(1)", "U" : "(2)","V" : "(3)",
  "W" : "(÷)","X" : "(*)","Y" : "(-)", "Z" : "(+)","a" : "7","b" : "8",
  "c" : "9","d" : "4","e" : "5","f" : "6","g" : "1","h" : "2","i" : "3",
  "j" : "÷","k" : "*","l" : "-","m" : "+","n" : "(7)","o" : "(8)","p" : "(9)",
  "q" : "(4)","r" : "(5)","s" : "(6)","t" : "(1)","u" : "(2)","v" : "(3)",
  "w" : "(÷)","x" : "(*)","y" : "(-)","z" : "(+)"
}

my_input = input("Type you mesage to be encoded: ")
output = "".join(str(encode[c]) for c in my_input) 
print (output)
kaya3
  • 47,440
  • 4
  • 68
  • 97

1 Answers1

0

You should use a dictionary instead of individual variables. For example

encode = {
  "A" : 0,
  "B" : 1
}

Then you can use a string joiner to translate the input

output = "".join(str(encode[c]) for c in my_input) 
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245