#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    4
    Rep Power
    0

    Problem with English to pig latin translator


    Hi Again, I am having a problem with a project which codeacademy requires me to do: For some reason when I input code which starts with a consonant it still returns the the translation as if it had a vowel as the first letter of the word:

    print "Welcome to the English to Pig Latin translator!"
    input = raw_input('Enter a word')
    """ If the first letter is a vowel, only 'ay' needs to be added to the end"""
    if input[0]=='a'or'e'or'i'or'o'or'u'or'A'or'E'or'I'or'O'or'U':
    print input+'ay'
    else:
    """ If the first letter is a consonant, the consonant must be removed from the start and then put 'ay' """
    print input[1:]+input[0]+'ay'

    I have googled it, but that seems to come up with pig latin translation code that is far more complicated than what I need for this problem with syntax that i haven't learn't. Any help is grealty appreciated!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    26
    Rep Power
    0

    pig latin


    Hopefully you have learned a tiny bit about lists:

    See if this helps you.
    Python 3:

    Code:
    word = raw_input("hello, please enter a word...:")
    list_of_vowels = ["a","e","i","o","u","A","E","I","O","U","y","Y"]
    if word[0] in list_of_vowels:
    	print(word + "ay")
    else:
    	word = word[1:] + word[0] + "ay"
    	print(word)
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,997
    Rep Power
    481
    sets are better than lists for searches. And known case is also better.

    if input[0].lower() in set('aeiou'):

    At any rate, the if statement would have had to be written as
    Code:
    if ((input[0]=='a')or
        (input[0]=='e')or
        (input[0]=='i')or
        (input[0]=='o')or
        (input[0]=='u')or
        (input[0]=='A')or
        (input[0]=='E')or
        (input[0]=='I')or
        (input[0]=='O')or
        (input[0]=='U')):
    and input already means something in python, hiding the definition is poor practice.
    Last edited by b49P23TIvg; June 20th, 2013 at 09:32 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    4
    Rep Power
    0
    Thank You!

IMN logo majestic logo threadwatch logo seochat tools logo