This could be an interesting error

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Aug 31 22:12:20 EDT 2014


Seymore4Head wrote:

>>'my' doesn't contain a vowel, therefore the condition of the 'if'
>>statement in 'pigword' is never true, therefore it never binds to the
>>name 'pigword'.
>>
> Ah.   The piglatin example says to use y as a vowel.  I forgot to
> include it.

Doesn't matter. What if one of the words doesn't contain any vowel or "y"?
E.g. "Grrr!", "Hmmm", "the nth degree", "tsk tsk", Internet slang such
as "pwn" and "pr0n", or words in Foreign like "cwm" (pronounced "koom",
Welsh for a cirque, which is a type of valley). You still need to deal with
the case that a word contains no vowels at all.

The easiest way is to initialise the "pigword" variable to the word itself,
then if the vowel test never succeeds, the function will return the word
unchanged.

def pigword(word):
    """Return word converted to piglatin."""
    pig = word  # initialise to the word itself.
    blah blah blah  # your code goes here
    return pig


-- 
Steven




More information about the Python-list mailing list