Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pig Latin
#1
Hi, I am trying to make a pig latin function in Python, which takes in a word and returns its pig latin translation. You can convert an English word into Pig Latin by moving all the consonants up to the first vowel to the end of the word and then appending "ay", e.g 'hello' becomes 'ellohay'.
This is my code:

def pig_latin(word):
""" Returns the pig latin translation of a word. """
i=0
new_word = word
vowel = ["a", "e","i","o","u"]
while word not in vowel:
word[i] = consonant
new_word = new_word[(i+1):] + consonant
i+=1
final_word = new_word + "ay"
return final_word

When I run it, it gives: NameError: name 'consonant' is not defined
I would really appreciate help regarding this.

Thank you!
[/i]
Reply


Messages In This Thread
Pig Latin - by manasihardikar - Nov-22-2017, 11:11 PM
RE: Pig Latin - by micseydel - Nov-23-2017, 01:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  non-latin characters in console from clipboard Johanson 3 858 Oct-26-2023, 10:10 PM
Last Post: deanhystad
  "If Len(Word) == 0" Code Block in Pig Latin Program new_coder_231013 3 2,226 Jan-02-2022, 06:03 PM
Last Post: deanhystad
  Pressing non-latin characters? Murlog 0 1,605 Jul-25-2020, 03:10 PM
Last Post: Murlog
  I want to filter out words with one letter in a string (pig latin translator) po0te 1 2,196 Jan-08-2020, 08:02 AM
Last Post: perfringo
  Help with pig latin translator DragonG 1 2,358 Nov-01-2018, 03:57 AM
Last Post: ichabod801
  Pig Latin Translator RickyWilson 1 3,271 Dec-02-2017, 08:20 AM
Last Post: buran
  Very basic programming help needed: pig latin program bstocks 2 8,118 Dec-02-2017, 08:12 AM
Last Post: RickyWilson

Forum Jump:

User Panel Messages

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