vowels = "aeiou" def wordToPig(word): # find the first vowel index = 0 word = word.lower() for char in word: # if we find a vowel, stop if char in vowels: break index += 1 suffix = "ay" # if the first character was a vowel, use 'yay' if index == 0: suffix = "yay" pig_word = (word[index:] + word[0:index] + suffix).capitalize() return pig_word def nameToPig(first, last): first_pig = wordToPig(first) last_pig = wordToPig(last) return first_pig + " " + last_pig # user input and print of first and last name in pig latin first_name = input("Enter your first name: ") last_name = input("Enter your last name: ") pig_latin_name = nameToPig(first_name, last_name) print("Your name in Pig Latin is:",pig_latin_name) # user input and print of word in pig latin user_word = input("Enter a word: ") pig_latin_word = wordToPig(user_word) print("Your word in Pig Latin is:",pig_latin_word)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question