Write a program that repeatedly prompts for an English word to translate into Pi
ID: 3621267 • Letter: W
Question
Write a program that repeatedly prompts for an English word to translate into Pig Latin, and prints the translated word. If the user enters a period, halt the program.(a) If a word begins with a vowel, append "yay" to the end of the word.
(b) If a word begins with a consonant, remove all consonants from the beginning up to the first vowel and append them to the end of the word. Finally, append "ay" to the end of the word.
i.e. dog > ogday
scratch > atchscray
is > isyay
apple > appleyay
hints: slicing is your friend: it can pick off the first character for checking, and you can slice off pieces and concatenate to yield the new word
making a string of vowels allows use of the "in" operator: vowels = 'aeiou'
This problem is head and shoulders above my current novice Python programming skills. Thanks.
Explanation / Answer
vowels = "aeiou" while True: resp = raw_input("Enter a word: ") if (resp == '.'): print "I'm quitting, bye." break else: for x in range(0, len(vowels)): if(resp[0] == vowels[x]): print (resp + " > " + (resp + "yay")) break again = True n = 0; while (again): for i in range(0, len(vowels)): if (resp[n] == vowels[i]): again = False; break n += 1 con = "" for j in range(0, n-1): con += resp[j] print resp[n-1:] + con + "ay" Something I throw together, tested on your words and results were the same.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.