Created
January 28, 2017 01:28
-
-
Save andela-sjames/e83b844888cc476216da10c6d02d9dd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pigLatin(word): | |
""" | |
Translate a single lowercase word to pig Latin. | |
if w begins with a consonant, | |
move the leading consonant to the end of the word | |
add 'ay' as a suffix | |
if w begins with a vowel, | |
add 'yay' as a suffix | |
'y' is a vowel; 'y' is not a consonant. | |
Test data (you should add more): | |
input: 'pig' output: 'igpay' | |
input: 'eagerly' output: 'eagerlyyay' | |
Params: w (string) a single lowercase English word (all alphabetic letters) | |
Returns: (string) w in pig Latin | |
""" | |
# check if the first character is a vowel | |
list1 = [] | |
if word[0] in "aeiouAEIOU": | |
return word + 'yay' | |
else: | |
list1 = list(word) | |
for char in list1: | |
if char not in "aeiouAEIOU": | |
val = char | |
list1 = list1[1:] | |
list1.append(val) | |
else: | |
break | |
return "".join(list1) + "ay"; | |
print pigLatin('pig') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment