asked 91.0k views
4 votes
Javascript

write a program that accepts text input and prints out the PigLatin translation.
*if a word begins with a vowel, the letter remains in place and 'way' is appended to the end of the word:
orange --> orangeway
*if a word begins with one consonant, that letter is moved to the end and 'ay' is appended:
pig latin --> igpay atinlay
* if a word begins with two consonants, both letters are moved to the end and 'ay' is appended:

asked
User Trenskow
by
7.6k points

1 Answer

7 votes

Answer:

def pig_latin(word):

if word[0] in ['a', 'e', 'i', 'o', 'u']:

return word + 'way'

elif word[0] in ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z']:

return word[1:] + word[0] + 'ay'

else:

return word[1:] + word[0] + 'ay'

word = input('Enter a word: ')

print(PigLatin(word))

Step-by-step explanation:

good luck :o

answered
User Bernardine
by
7.4k points