Translating sentences in PygLatin


#1



Hello everybody! I was able to make a translator, but it only translates one word. I really don't understand how to make it possible to translate a sentence with multiple words.

Hope someone can help me!


#List Operators
vowels = ["a", "e", "i", "o", "u"]
consonants = ["b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"]

#Instructions
print ("Program to translate sentences to pig latin.")
print ("Avoid using symbols and punctuation.")

#Define word
word= ""
while word != "exit":
    word = input("Enter a word to translate or Exit: ")
    if word.isalpha():
        word = str(word)
    
#Translate word by checking how it starts
        first_letter = word[0]
        second_letter = word[1]
        if first_letter in vowels:
            print (word + "yay\n")
        else:
            if first_letter and second_letter in consonants:
                print (word[2:] + word[:2] + "ay\n")
            else:
                print (word[1:] + word[0] + "ay\n")

    else:
        if word.lower() == "exit":
            word = word.lower()
            print("Goodbye.")
        else:
            print("Invalid character! Try again.\n")


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.