Python Forum
Convert a sentence to pig latin - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Convert a sentence to pig latin (/thread-29994.html)



Convert a sentence to pig latin - SalsaBeanDip - Sep-28-2020

I am writing a function that will convert a sentence to pig latin. To do this, I convert all the letters to uppercase, remove the first letter and place it at the end of the word, and then add "AY" to the end of the word. So, "Stop and smell the roses." will become "TOPSAY NDAAY MELLSAY HEAY OSESRAY.” I can't seem to get my code to work though, it only prints out "OSESRAY". How can I fix my program?

def pigLatin():
    user_string = input('Enter a string: ')
    user_string = user_string.upper()
    ay = 'AY'
    user_string = user_string.split()

    for item in user_string:
        result_pig = item[1:(len(user_string))] + item[0] + ay + ' '
    print(result_pig)

Hello everyone I was able to fix it


RE: Convert a sentence to pig latin - deanhystad - Sep-29-2020

Pig Latin for Stop is Opstay. If a word does not start with a consonant the start of the word is left unchanged and 'way' or 'yay' is added to the end. "I" becomes "Iway" or "Iyay". You should also maintain the case of the first letter.

This complicates the translation a bit. Not only do you use different solutions based on if the word starts with a consonant, but you need to look for consonant clusters and also fix the case.


RE: Convert a sentence to pig latin - jefsummers - Sep-29-2020

I think it remains simple - Check each character until you reach a vowel, then move the consonants to the end and add "ay". If no consonants, add yay (or ay as I learned it).


RE: Convert a sentence to pig latin - deanhystad - Sep-29-2020

Certainly harder than taking the first letter, move to the end and append 'ay'. Not hard by any means, but relatively it may be 5 times harder?


RE: Convert a sentence to pig latin - SalsaBeanDip - Oct-04-2020

Hello everyone, this was a homework assisgnment and I translated the sentence the way my teacher asked me to. I do realize it is more complicated than the way I was told to do it. But I was able to figure out the problem. Thank you!