I have written a program on Pig Latin converter which I've attached herewith Pastebin. I am still a beginner, and I know that the code works perfectly, but can we make some improvements in this code cause I don't like using break statements too much. Also, is there any way to make this code smaller. Looking for your kind suggestions. Thanks.
'''Pig Latin is a language constructed by transforming English words. While the ori-
gins of the language are unknown, it is mentioned in at least two documents from
the nineteenth century, suggesting that it has existed for more than 100 years. The
following rules are used to translate English into Pig Latin:
• If the word begins with a consonant (including y), then all letters at the beginning of
the word, up to the first vowel (excluding y), are removed and then added to the end
of the word, followed by ay. For example, computer becomes omputercay
and think becomes inkthay.
• If the word begins with a vowel (not including y), then way is added to the end
of the word. For example, algorithm becomes algorithmway and office
becomes officeway.
Write a program that reads a line of text from the user. Then your program should
translate the line into Pig Latin and display the result. You may assume that the string
entered by the user only contains lowercase letters and spaces.
'''
def pig_latin(word):
word = word.strip().lower()
const_tail = 'ay'
vow_tail = 'way'
pig_latin =''
vowel = ['a','e','i','o','u']
for i in range(len(word)):
if word[0] in vowel:
pig_latin+=word+vow_tail
break
else:
if word[i] in vowel:
pig_latin+=word[i:]+word[0:i]+const_tail
break
return pig_latin
def main():
word = str(input('Enter the word: '))
print('The pig latin translation of the string is',pig_latin(word))
if __name__ == "__main__":
main()
if
to thereturn
need another level. \$\endgroup\$