Taking characters out of list and turning them into other characters
You're inputting two letters, but your test conditions only contain one character each. You should iterate on the input string using a for
and test each character in the string one at a time:
before = input()
for i in before:
if i=="A":
print("Q")
elif i=="B":
print("W")
elif i=="C":
print("E")
elif i=="D":
print("R")
else:
print("--")
You can also improve your code by using a mapping instead of the if/elif
as this will help you accommodate new translations more easily:
before = input()
mapping = {'A': 'Q', 'B': 'W', 'C': 'E', 'D': 'R'}
after = ''.join(mapping.get(x, '--') for x in before)
print(after)
Notice how the dictionary's get
method was used to return the default '--'
when the mapping does not contain the character.