forked from amcclintock/Breakfast_Programming_Guild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbroken_1_10.py
33 lines (20 loc) · 1005 Bytes
/
broken_1_10.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#Pig Latin translator
#English is translated to Pig Latin by taking the first letter of every word, moving it to the end of the word and adding ‘ay’. “The quick brown fox” becomes “Hetay uickqay rownbay oxfay”.
#Flip the word into pig latin
def translate_word(word):
vowels = 'aeiou'
first_letter, *remaining_letters = word.lower()
if first_letter in vowels:
return word + 'yay'
else:
return ''.join(remaining_letters) + first_letter + 'ay'
#Break apart the sentence into words, then combine new words back together again
def translate_sentence(sentence):
translated_sentence = ""
for word in sentence.split(" "):
translated_sentence += translate_word(word) + " "
return translated_sentence.strip()
#Call the functions, and return the value
print(translate_sentence('The quick brown fox'))
#Challenge
# Take sentence(s) from user, ensure no punctuation. Use a loop(s) to take in many sentences