Week 1, Extra Problem 1: Pig Latin
[15 points; individual or pair]

 

This problem is inspired by

Warm Up

[5 points]

Write pigLatin( s ), which will take as input a string s. s will be a single word consisting of lowercase letters. Then, pigLatin should output the translation of s to pig latin, according to these slightly altered rules:

If the input word has no letters at all (the empty string), your function should return the empty string

If the input word begins with a vowel, the pig latin output simply appends the string 'way' at the end. 'y' will be considered a consonant, and not a vowel, for this problem.

Hint: Consonant letters in the English alphabet are B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z, and Y.


Example

pigLatin('one') returns 'oneway'

If the input word begins with a consonant, the pig latin output is identical to the input, except that the input's initial consonant is at the end of the word instead of the beginning and it's followed by the string 'ay'.


Example

pigLatin('be') returns 'ebay'

Of course, this does not handle words beginning with multiple consonants correctly. For example, pigLatin('string') returns 'tringsay'.++
Don't worry about this. However, if you would like to tackle this more challenging problem, see the extra credit, below... .

 

The real pig latin challenge

[10 points]

Create a function called spamLatin( s ) that handles more than one initial consonant correctly in the translation to Pig Latin. That is, spamLatin moves all of the initial consonants to the end of the word before adding 'ay'. (You may want to write and use a helper function to do this.)

Also, spamLatin should handle an initial 'y' either as a consonant OR as a vowel, depending on whether the y is followed by a vowel or consonant, respectively. For example, 'yes' has an initial y acting as a consonant. The word 'yttrium', however -- element #39 for anyone who's as chemically challenged as I am -- has an initial y acting as a vowel. Here are some additional examples:

>>> spamLatin('string')

ingstray

 

>>> spamLatin('yttrium')

yttriumway

 

>>> spamLatin('yoohoo')

oohooyay

 

If you think about this problem thoroughly, you'll find that not every possible case has been accounted for - you are free to decide the appropriate course of action for those "corner cases."

 

Submitting your file

You should submit your hw1ec1.py file at Canvas.

Next

Extra problem 2