This could be an interesting error
Seymore4Head
Seymore4Head at Hotmail.invalid
Sun Aug 31 18:04:18 EDT 2014
On Sun, 31 Aug 2014 22:38:12 +0100, Mark Lawrence
<breamoreboy at yahoo.co.uk> wrote:
>On 31/08/2014 22:02, Seymore4Head wrote:
>> import math
>> import random
>> import sys
>>
>> ex='Hey buddy get away from the car'
>> newex = ex.split()
>> sentence=""
>>
>> print (newex)
>> wait = input (" Wait")
>>
>> def pigword(test):
>> for x in range(len(test)):
>
>Please read up on how to use for loops as the above is usually a code smell.
>
>> 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)
>
>This is Python so please get rid of those unnecessary brackets. Having
Having brackets must have been required in earlier versions maybe. I
will give it a try without it.
Without this video, I don't think I would have been able to write any
of this code yet.
I was watching her thinking, that would be really useful for the
piglatin example:
https://www.youtube.com/watch?v=rkx5_MRAV3A
51 min
>done that assume that you have an empty test so your loop never gets
>entered, the local pigword never gets assigned before the return hence
>your UnboundLocalError.
>
>>
>> for x in range(len(newex)):
>
>Ditto.
>
>> sentence = sentence + pigword(newex[x])+ " "
>> print (sentence)
>> wait = input (" Wait")
>>
>> The program seems to work and it does work with everything I have
>> tried so far. The one exception is if you change "the" to "my" (in
>> the first line) the program crashes.
>>
>>
>> Traceback (most recent call last):
>> File "C:\Documents and
>> Settings\Administrator\Desktop\Functions\test.py", line 25, in
>> <module>
>> sentence = sentence + pigword(newex[x])+ " "
>> File "C:\Documents and
>> Settings\Administrator\Desktop\Functions\test.py", line 22, in pigword
>> return (pigword)
>> UnboundLocalError: local variable 'pigword' referenced before
>> assignment
>>>>>
More information about the Python-list
mailing list