-2

I'm stuck on a really hard question for my class in which I need to create a Pig Latin converter in Python for a given string.

Basically, here are the rules.

  1. For any word that begins with one or more consonants (y is considered a consonant): move the consonants to the end of the word and append the string 'ay'.

  2. For all other words, append the string 'way' to the end.

The function also must be case deal with punctuation and case sensitivity, it is suggested that we create a separate function to find the initial vowel of any word and use it in the main function, which I kinda did, however, I'm having trouble implementing the Case and punctuation into my main formula and what to do if a word has no vowels (since "y" doesn't count as a vowel in our case, the word "my" doesn't have a vowel.

Here's my code so far.

def vowelfinder(astring):
    vowels = ["A","E","I","O","U","a","e","i","o","u"]
    alist = astring.split()
    for i in alist:
        for j in range(len(i)):
            if i[j] in vowels:
                print(j)
                break

def igpay(astring):
    vowelfinder(astring)
    for i in alist

Any advice is helpful

user3483844
  • 133
  • 1
  • 1
  • 13
  • 1
    Why don't your classmates and you post ONE question per assignment? This is like the fifth pig-latin question today. Just search for "pig latin" on SO and you will find the answers to the other pupils' questions. – Hyperboreus Apr 01 '14 at 07:13
  • [this answer shows how to deal with punctuation using `re.split()` and `str.isalnum()`](http://stackoverflow.com/a/22776429/4279). – jfs Apr 20 '14 at 01:55

1 Answers1

0
# For any word that begins with one or more consonants (y is considered a consonant):
if "aeiouAEIOU".find(astring[0]) == -1:
    # move the consonants to the end of the word and append the string 'ay'.
    return astring[1:] + astring[0] + "ay"
# For all other words,
else:
    # append the string 'way' to the end.
    return astring + "way"

This is for a word. Splitting into words should be easy enough.

EDIT: brainfart.

Amadan
  • 191,408
  • 23
  • 240
  • 301