vowel = ('A','E','I','O','U','a','e','i','o','u')
sentence = 'Write a script that encodes phrases'
def pig_latin(sentence):
for words in sentence.split():
if words[0] in vowel:
words = words + 'ay'
else: words = words[1:]+ words[0] + 'ay'
return(words)
pig_latin(sentence)
I am trying to let this function print out all the words in the sentence but no matter where I place return
, it always only gives me the first/ last word in the sentence. Can someone tell me what I did was wrong? Thank you!
print
statements inside your loop. The critical problem is that you are trying to usewords
for two conflicting purposes at the same time. Each purpose destroys the other's progress. Use one loop variable, and another to accumulate results.