Having issues with my English to PigLatin Converter. I can get the code to execute correctly on one word but once i do 2 or more words it adds the first letter [0] + 'ay' to the last word in the line.... any suggestions?

def main():
    # Create a list of words
    words = []
    # user input a sentence.
    sentence = input("Please enter a sentence in english to convert to 'Pig Latin': ")
    # for loop that splits up sentence and appends it to words list
    for wrd in sentence.split():
        wrd = words.append

    # Display the Sentence in english to the user
    print("Here is the sentence you entered: ", sentence)
    # Dsiplay the new sentence in PigLatin

def PigLatinConverter(words):
    # Create a for loop to iterate of words
    for i in range(len(words)):
        # Add the first letter and ay to the end
        PigLatin = words[1:] + words[0] + "ay"
    # return PigLatin to main function
    return PigLatin

# Calls the main function to execute

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

6 Years
Discussion Span
Last Post by THEPalletizer

You are passing sentence not words. You do not need to store append method zillion times to wrd.

Edited by pyTony: n/a


Please use the CODE button to show indents, line numbers, syntax coloring...


  • You can get the list of words by simply saying words = sentence.split()
  • You need to think about punctuation, in case user inputs some. For instance, if you got the words from the first sentence of this hint, "punctuation," and "some." have trailing punctuation.
  • I would write the function english_to_piglatin so the parameter is a single word rather than a list of words.
  • The usual idiom for modules that need to (also) run as a script is if __name__ == "__main__": main() You might as well get into the habit of invoking main() that way.

Edited by happygeek: fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.