Dec-01-2018, 08:08 PM
Hi everyone,
So basically I have a problem building a translator, where I want the input "s" to give me "с" and the input "h" to give me "х" but at the same time I want "sh" to give me "ш".
Previously I was given a command to put into my code so I could make "cei" give me "си". I've tried to use the same technique again, but it's not working.
Here is what I have so far (It might look confusing because some of the Cyrillic and Latin letters look the same, but I made sure everything was typed out correctly):
So basically I have a problem building a translator, where I want the input "s" to give me "с" and the input "h" to give me "х" but at the same time I want "sh" to give me "ш".
Previously I was given a command to put into my code so I could make "cei" give me "си". I've tried to use the same technique again, but it's not working.
Here is what I have so far (It might look confusing because some of the Cyrillic and Latin letters look the same, but I made sure everything was typed out correctly):
def translate(phrase): translation = "" for letter in phrase: if letter in "A": translation = translation + "а" elif letter in "Bb": translation = translation + "б" elif letter in "Cc": translation = translation + "к" elif letter in "Ll": translation = translation + "л" elif letter in 'Ii': translation = translation + "и" elif letter in "Ee": translation = translation + "е" elif letter in "Ss": translation = translation + "с" elif letter in "Hh": translation = translation + "х" elif letter in 'Ii' and translation[-2:] == 'ке': translation = translation[:-2] + "cи" elif letter in "Hh" and translation[-1:] == "с": translation = translation[:-1] + "ш" else: translation = translation + letter return translation print(translate(input("Enter word: ")))I hope you guys can help. Thanks in advance.