import re
text = input("Enter text: ")
text = text.lower()
len = len(text)
lenid = len - 1
def translate(text):
translation = ""
slocid = text.index("s")
for letter in text:
if (text[lenid] == "s") or (text[slocid + 1] == " "):
translation = re.sub(r"s\b", lambda m: m.group().replace("s", "ς"), text)
if letter == "s":
translation = translation.replace("s", "σ")
if letter == "a":
translation = translation + "α"
else:
translation = translation + letter
return translation
print(translate(text))
I want to make a program where, when I enter a text, I get back the same text but
- all the
"s"
at the end of a word are replaced with"ς"
- if they're not at the end of the word, I want the
"s"
to be replaced with"σ"
. - If the letter is
"a"
I want it replaced with"α"
.
I'm trying to make a Greeklish to Greek translator and it just seems I messed up.
input: "as"
output: "aςs"
what I want: "ας"
input: "sa"
output: "sa"
what I want: "σα"
input: "sakas"
output: "σakaςs"
what I want: "σαkας"