Hello! I spent several hours on the exercise “Pig Latin” in python, and all the solutions I proposed do not work. Please, I need help. Here is my code:
def translate(text: str) -> str:
def translate_word(word):
vowels = {'a', 'e', 'i', 'o', 'u'}
if word[0] in vowels or word[:2] == 'xr' or word[:2] == 'yt':
return word + 'ay'
if word[:2] == 'qu':
return word[2:] + 'quay'
else:
i = 0
while i < len(word) and word[i] not in vowels:
if word[i:i+2] == 'qu':
i += 2
break
i += 1
if word[i-1:i+1] == 'qu':
i += 1
return word[i:] + word[:i] + 'ay'
words = text.split()
translated_words = [translate_word(word.lower()) for word in words]
return ' '.join(translated_words)