[Tutor] Local Unbound Mystery

Alan Gauld alan.gauld at btinternet.com
Sat Sep 20 14:26:57 CEST 2008


> Not really the code has an error so it could not have worked.
>
>> updown = +1

Is this meant to be

updown += 1

maybe?

Although as the error message shows you need to set it to a
valid value before incrementing it, so mayber you just meant

updown = 1  # no need for the + sign

>> while keyop <> 0:

And the <> form of not equal is deprecated in favour of != so
this should probably be

while keyop != 0

Or better still just

while keyop:

> You forgot to create keyop in this example.
>> UnboundLocalError: local variable 'updown' referenced before 
>> assignment

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list