I have written a program in the Pig Latin converter that I attach with Pastebin. I'm still a beginner, and I know the code works perfectly, but can we make some improvements to this code because I don't like to use interrupt declarations too much? Also, is there a way to make this code smaller? Looking for your kind suggestions. Thank you.
'''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()