Question

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

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]

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 string's 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 word's 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 can't seem to get it to pass all of the doctests. Python runs the code without problem, so they're pretty sure that there aren't 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
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
  • use C++ Pig Latin Background Pig latin is a "language” where you take the regular English...

    use C++ Pig Latin Background Pig latin is a "language” where you take the regular English Word, remove the first letter, place it on the end of the word, and then append "ay" to the end of the word. Pig Latin = Igpay Atinlay Functionality 1) Prompt the user to enter any input string (I will test it with multiple words). 2) After receiving and storing (if needed) their input, change their words to Pig Latin by placing the first...

  • **PLEASE DO IT IN JAVA Assignment 10.1 [95 points] The WordCruncher class Write the Java code for...

    **PLEASE DO IT IN JAVA Assignment 10.1 [95 points] The WordCruncher class Write 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...

  • c++ program help(english words to pig latin).

    Program Lab #7StringsYou have been asked to construct a program that will translate English to Pig Latin.Following good programming practice, yourealize that the solution will make heavy use of functions.You plan to start by constructing a function that will convert anEnglish word into 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...

  • 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