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
#2
What else would you expect? You never defined it anywhere. Maybe you meant to swap the sides of the assignment?

Also, in the future please make sure to always use code tags on code; as you can see here, the indentation is lost, and it's essential to understanding anything other than the move trivial code.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  non-latin characters in console from clipboard Johanson 3 688 Oct-26-2023, 10:10 PM
Last Post: deanhystad
  "If Len(Word) == 0" Code Block in Pig Latin Program new_coder_231013 3 2,048 Jan-02-2022, 06:03 PM
Last Post: deanhystad
  Pressing non-latin characters? Murlog 0 1,517 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,096 Jan-08-2020, 08:02 AM
Last Post: perfringo
  Help with pig latin translator DragonG 1 2,263 Nov-01-2018, 03:57 AM
Last Post: ichabod801
  Pig Latin Translator RickyWilson 1 3,177 Dec-02-2017, 08:20 AM
Last Post: buran
  Very basic programming help needed: pig latin program bstocks 2 7,986 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