Question

Correct the syntax errors to allow the code to pass all of the provided doctests.

You may have heard of Pig Latin, a set of rules for modifying regular English to render it unintelligible to those who do not know the rules. This problem asks you to fix a function that will convert an English word to Pig Latin The rules for converting a word to Pig Latin are as follows: 1. If the word starts with a vowel, add way to the end of the word 2. Otherwise, all letters before the first vowel of the word are moved to the end of the word and ay is added to the end Write a function named igpay_atinlay ) that takes a single parameter, a string containing an English word, and returns the strings Pig Latin translation in accordance with the rules above. For this problem, assume the letter Y is always a vowel. Your solution should also preserve the words capitalization. You may assume that the only letter that might be capitalized is the first letter of the word and that the word will only contain alphabetic letters-no digits, spaces, punctuation marks, or other special characters Your friend wrote the code below, but cant seem to get it to pass all of the doctests. Python runs the code without problem, so theyre pretty sure that there arent any syntax errors. Help them correct their errors and make the code pass all of the provided doctests def igpay_atinlay (word): >>>igpay_atinlay (Pig) Igpay >>>igpay_atinlay (Latin) Atinlay >>>igpay_atinlay(me) emay >>>igpay_atinlay(egg) eggway >>>igpay_atinlay(Shoot) Ootshay >>>igpay_atinlay(Spy) Yspay >>igpay atinlay(Amy) Amyway >>>igpay atinlay (twyndyllyng yndyllyngtway import string if word [1] in aeiouy return word +way while word[O] not in aeiouy: return word + ay else: word = word [ 1 : ] + word [ 0]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def igpay_atinlay(word):
#preserve first letter capitalization
   upper = word[0].isupper()
   #convert to lower and check vowel
   if word[0].lower() in 'aeiouy':
       word = word + 'way'
   else:
   #move letters to last untill first vowel
       while word[0] not in 'aeiouy':
           word = word[1:] + word[0]
       word = word + 'ay'
   # if given first letter capital return word with first letter capitalized
   if(upper):
       return word.title()
   else:
       return word

print(igpay_atinlay("Pig"))
#Igpay
print(igpay_atinlay("Latin"))
#Atinlay
print(igpay_atinlay("me"))
#emay
print(igpay_atinlay("egg"))
#eggway
print(igpay_atinlay("Shoot"))
#Ootshay
print(igpay_atinlay("Spy"))
#Yspay
print(igpay_atinlay("Amy"))
#Amyway
print(igpay_atinlay("twyndyllyng"))
#yndyllyngtway

Add a comment
Know the answer?
Add Answer to:
Correct the syntax errors to allow the code to pass all of the provided doctests. You...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In java: A fun language: f you recently ate at Chipotle, you may have received a...

    In java: A fun language: f you recently ate at Chipotle, you may have received a brown paper bag with gibberish letters written on it: “AKINGMAY AWAY IGPAY EALDAY ABOUTWAY IGPAY ATINLAY”. In fact this message is written in Piglatin, a simple but fictitious language. Piglatin converts a word in English using the following two rules: If the letter begins with a vowel, then “WAY” is appended to the word. If the letter begins with a consonant (a letter other...

  • Write the Java code for the class WordCruncher. Include the following members:

    **IN JAVAAssignment 10.1 [95 points]The WordCruncher classWrite the Java code for the class WordCruncher. Include the following members:A default constructor that sets the instance variable 'word' to the string "default".A parameterized constructor that accepts one String object as a parameter and stores it in the instance variable. The String must consist only of letters: no whitespace, digits, or punctuation. If the String parameter does not consist only of letters, set the instance variable to "default" instead. (This restriction will make...

  • Design and code a SWING GUI to translate text entered in English into Pig Latin. You...

    Design and code a SWING GUI to translate text entered in English into Pig Latin. You can assume that the sentence contains no punctuation. The rules for Pig Latin are as follows: For words that begin with consonants, move the leading consonant to the end of the word and add “ay”. Thus, “ball” becomes “allbay”; “button” becomes “uttonbay”; and so forth. For words that begin with vowels, add “way’ to the end of the word. Thus, “all” becomes “allway”; “one”...

  • I have this problem for a final thats in my book thats i'm stuck on ....

    I have this problem for a final thats in my book thats i'm stuck on . Any help would be really appreciated. Design and code a Swing GUI to translate text that is input in English into Pig Latin. You can assume that the sentence contains no punctuation. The rules for Pig Latin are as follows: ⦁ For words that begin with consonants, move the leading consonant to the end of the word and add “ay.” For example, “ball” becomes...

  • For this week's lab, you will use two of the classes in the Java Collection Framework:...

    For this week's lab, you will use two of the classes in the Java Collection Framework: HashSet and TreeSet. You will use these classes to implement a spell checker. Set Methods For this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set is a Set, then the following methods are defined: set.size() -- Returns the number of items in the set. set.add(item) -- Adds the item to the...

  • For this week's lab, you will use two of the classes in the Java Collection Framework:...

    For this week's lab, you will use two of the classes in the Java Collection Framework: HashSet and TreeSet. You will use these classes to implement a spell checker. Set Methods For this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set is a Set, then the following methods are defined: set.size() -- Returns the number of items in the set. set.add(item) -- Adds the item to the...

  • CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the fil...

    CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT