Perhaps a better solution is to use a dictionary instead of letter names as variable names:
transDict = { "a": "01100001", "b": "01100010", "c": "01100011", "d": "01100100", # etc., etc. } text = input( "Enter your message: " ) result = "".join( [transDict[letter] for letter in text] ) print(result)
(I also adjusted the ASCII codes - yours were in capital letters.)
Explanation
(for the longest statement):
Use "" as a delimiter (i.e. no delimiter ) to connect all the elements in the list of translated letters, where the letters get one after another from text ".
Thus, the result will be the same as if you used these commands:
listOfCodes = []
source share