l T-Mobile Wi-Fi 4:54 PM University of Houston 1 of 2 COSC 1306 Assignment #6 Ob
ID: 3735692 • Letter: L
Question
l T-Mobile Wi-Fi 4:54 PM University of Houston 1 of 2 COSC 1306 Assignment #6 Objective: Practice using strings with loops, functions, and conditional execution Description: In this assignment you will ask the user to input an English word, translate that word into "Pig Latin" and then print both words Your program must meet the following requirements I. Include a multi-line comments at the top of the file with your name, PSID number, and the assignment number 2. Your program should ask the user for a word in English 3. Your program should use a function to translate that word into "Pig Latin" and rcturns the translated word. You should then print both words. See below for the translation rules. 4. Your program should prompt the user to repeat or exit the program 5. For the same input you program should match the output shown below Hint: Implement the translation one step at a rime and sest each step Deadline: Sunday, March 25, 2018,11:59PM Example Output: The following is one possible run with example sets of inputs. This progran will translate a word from English to Pig Latin. Please enter a word: Cat Cat becomes Atcay Would you like another word? (Y/N) y Please enter a word: by by becomes byway Nould you like another word? (Y/N) Y Please enter a word: Away Away becomes Awayway Would you like another word? (Y/N) Y Please enter a word: tree tree becomes eetray Would you like another word? (Y/N) n Ankthay ouyayExplanation / Answer
Hi friend, Image is not visible clearly. However this program is about to finf "Pig Latin" word.
Please find my Python program to find Pig Latin word:
#!/usr/bin/python
def main():
# declaraing the variable and initializing to their default values
word=""
vowels = 'aeiou'
v_index = -1
flag = 1
# running an infinite loop
while(flag):
# Taking word as input from user
word = raw_input("Enter a word: ")
# computing length of the word and converting word to lower case
w_len = len(word)
word = word.lower()
# if the word entered is 'quit' it will quit out from the loop and program terminates
if word == 'quit':
break
# iterating through each letter in word to find the first position of vowel
for i, ch in enumerate(word):
if ch in vowels:
v_index = i
break
# if v_index != -1 that means given word has a vowel
if v_index != -1:
# if v_index is 0 that means vowel is at first position in the word
if v_index == 0:
print word + 'way'
# if v_index is > 0 that means vowel is not at first position but somewhere in the middle or last
elif v_index > 0:
print word[v_index:w_len] + word[0:v_index] + 'ay'
if __name__=='__main__':
main()
Execution and output:
186590cb0725:Python bonkv$ python pig_latin.py
Enter a word: dog
ogday
Enter a word: scratch
atchscray
Enter a word: is
isway
Enter a word: apple
appleway
Enter a word: Hello
ellohay
Enter a word: a
away
Enter a word: quit
186590cb0725:Python bonkv$ python pig_latin.py
Enter a word: bat
atbay
Enter a word: QUIT
186590cb0725:Python bonkv$ python pig_latin.py
Enter a word: ball
allbay
Enter a word: Quit
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.