different errors, return outside function and others

Tony sternbrightblade at gmail.com
Mon Feb 23 04:07:57 EST 2009


ok thank you for that input, this is my first class in programming and its
the only one the school offers. im pretty sure those are supposed to be
modules
that im writting. would it make a difference if those were modules and not
functions? kinda stupid question there but im trying to learn as much as
possible.
Also anything with def infront of it example def start(): would be a
function correct? also im Using 2.5 and the IDLE to do this

On Mon, Feb 23, 2009 at 12:23 AM, Gabriel Genellina
<gagsl-py2 at yahoo.com.ar>wrote:

> En Mon, 23 Feb 2009 04:51:39 -0200, Tony <sternbrightblade at gmail.com>
> escribió:
>
> Hi,
>> I am trying to write a small program for my final for school, everytime i
>> run my program it gives me a return outside function error (after i fixed
>> all the indentation errors it throws at me), i am not very good at
>> programing with python atm, so any help would be appreiciated. and if im
>> missing somethign please feel free to throw
>> any suggestions out there.
>>
>
> Is this your *actual* code? It does not even compile...
> Things like 'def foo(...):' are *functions*, not *modules*.
>
> Variables inside functions (including its arguments) are locals, private to
> the function. Even if you modify them, the "outside world" doesn't notice.
> So a function like this:
>
> def fight(HP, ZHP, weapon, boss=False):
>>    if weapon == 'fist':
>>        while HP > 0 and ZHP > 0:
>>            damage = 2
>>            ZHP = ZHP - damage
>>            if boss:
>>                HP = HP - dice_roll2()
>>            else:
>>                HP = HP - 2
>>    elif weapon == 'baseball bat':
>>
>          [... more code ...]
>
> won't alter the "global" values HP, ZHP; in fact, it won't do nothing.
>
> Either return the new values:
>   return HP, ZHP
> and also adjust everywhere you call:
>   HP, ZHP = fight(HP, ZHP, ...)
>
> Or mark HP, ZHP as globals (using the global statement).
>
> --
> Gabriel Genellina
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090223/d0bf980d/attachment-0001.html>


More information about the Python-list mailing list