Python Forum
Yet another pig latin thread
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Yet another pig latin thread
I've read many of the pig latin threads on this forum and many make the common mistake of only moving the first letter if is a consonant, others fail to account for a single letter word being left alone.
I made this function to account for the following rules:

1) If a word is only one letter long, then leave it as is. Otherwise:
2) If a word begins with a vowel, just as "yay" to the end. For example, "one" is translated into "oneyay".
3) If it begins with a consonant, then we take all consonants before the first vowel and we put them on the end of the word. For example, "ditch" is translated into "itchday" and "bridge" is translated to "idgebray"

vowels = "aeiou"

def igpay(word):
	if len(word) > 1:
		word = word.lower()
		if word[0] in vowels:
			word += "y"
			index = 0
			while word[index] not in vowels:
				index += 1
			word = word[index: ] + word[ : index]
		word += "ay"
	return word
Any improvements or comments would be appreciated.

An interesting challenge might be to write a function to translate back to English

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020