Nov-11-2018, 03:28 AM
A dictionary would work better for something like this:
tdict = { 'a': 'a', 'b': 'б', 'c': 'к', 'l': 'л', 'i': 'и' } def translate(phrase): translation = '' for letter in phrase.lower(): if letter in tdict: translation = f'{translation}{tdict[letter]}' else: print(f'{letter} is not in dictionary') return translation print(translate('cab')) print(translate('ilabc')) print(translate('xlbd')) # try missing letterresults:
Output:кaб
илaбк
x is not in dictionary
d is not in dictionary
лб