This could be an interesting error
Seymore4Head
Seymore4Head at Hotmail.invalid
Sun Aug 31 18:31:51 EDT 2014
On Sun, 31 Aug 2014 16:10:27 -0600, Michael Torrie <torriem at gmail.com>
wrote:
>On 08/31/2014 03:02 PM, Seymore4Head wrote:
>> def pigword(test):
>> for x in range(len(test)):
>> if test[x] in "AEIOUaeiou":
>> stem = test [x:]
>> prefix = test [:x]
>> pigword = stem + prefix + "ay"
>> print ("Stem ",stem)
>> print ("Prefix",prefix)
>> print (pigword)
>> break
>> return (pigword)
>
>So, what do you think will happen if the word contains no vowels? Where
>is pigword defined?
>
>> for x in range(len(newex)):
>> sentence = sentence + pigword(newex[x])+ " "
>> print (sentence)
>> wait = input (" Wait")
>
>You don't need to iterate over range(len(blah)). The standard idiom
>when you need index as well as the item itself is to iterate over
>enumerate(). Or if you don't need the index, just iterate directly.
>You can iterate directly over the list, or the letters in the word,
>optionally getting an index. It's much cleaner and less error prone.
>Consider something like:
>
>def pigword(word):
> for x,letter in enumerate(word):
> # x is index (position), letter is the value at that index
> if letter in "AEIOUaeiou":
> ...
>
>for word in list_of_words:
> sentence = sentence + pigword(word) + " "
> ...
>
>That doesn't solve your little logic problem, though I think you can
>figure that part out easily!
>
Thanks I will give that a try.
More information about the Python-list
mailing list