Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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:

1. 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 returns 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 time and test each step.

Example Output:

The following is one possible run with example sets of inputs.

This program 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.

Would 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 ouyay!

Notes: Translation rules for Pig Latin: Pig Latin is a fictitious language derived from English using a few simple rules. 1.) If a word starts with a vowel (a, A, e, E, i, I, o, O, u, U) then the translation is formed by adding a "way" to the end of the word. e.g. "at" becomes "atway", "egg" becomes "eggway"

2.) If a word contains no vowels (a, A, e, E, i, I, o, O, u, U) then the translation is formed by a adding a "way" to the end of word. e.g. "my" becomes "myway", "by" becomes "byway"

3.) If a word starts with a consonant and contains a vowel, the translation is formed by moving the consonant(s) up to the first vowel to the end of the word and adding an "ay". e.g. "bat" becomes "atbay", "that" becomes "atthay", "three" becomes "eethray"

4.) Words that start with an initial capital letter should be translated to words with an initial capital letter. e.g. "Houston" becomed "Oustonhay", "Iceland" becomes "Icelandway", "Marry" becomes "Arrymay"

Other Hints: You have been asked to construct a program that will translate English to Pig Latin. Following good programming practice, you realize that the solution could make heavy use of helper functions. You consider helpful functions that might: Determine if a given letter is a vowel. Determine if a word starts with a vowel (rule 1). Determine if a word contains a vowel (rule 2). Determine where the vowel is in the word (rule 3). Determine if the word has an initial capital letter (rule 4).

I have the code for rule 1 & rule 2, I need help on rule 3 & 4

def is_vowel(letter): return letter.upper() in 'AEIOU' # if the letter is a vowel return True

def has_vowel(word): for letter in word: # Loop through all the letters if is_vowel(letter): # See if a letter is a vowel return True # If so, return True, "has a vowel" is True # After looking through all the letters in the word return False # we found no vowel, so the word does not have a vowel

def translate(word): if is_vowel(word[0]): # The word starts with a vowel (Rule #1) # add way to the end of the word return word + 'way' elif has_vowel(word): # The word must have a vowel that is not the first letter (Rule #3) # ToDo: Fix this return '?'*len(word) else: # The word contains no vowel (Rule #2) # add way to the end of the word return word + 'way'

print("This program will translate a word from English to Pig Latin.")

choice = 'Y' while choice.upper() == 'Y': #Loop as long as the user says Yes word = input("Please enter a word: ") print(word, "becomes", translate(word)) choice = input("Would you like another word? (Y/N) ")

print("Ankthay ouyay!")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students also viewed these Databases questions

Question

Define Industry 4.0.

Answered: 1 week ago