Newbie question about function return values

Brian Munroe bmunroe at tribador.nu
Fri Mar 14 01:25:38 CET 2003


Ok, so it is late in the day and I, for the life of me, cannot figure out
what is going on in the code below.

I should get the value of x, but instead I am getting 'None' (in
sectors(500))

So then I create another function, and I get the correct value for the
return value (in hello(2))

WTF?

thanks in advance

-- brian


<--- code ------------------------------------------>

#!/usr/bin/python

def sectors(x):
    if ((x % 512) != 0):
        x = x + 1
        sectors(x)
    else:
        return x

def hello(x):
    x = x * x
    return x


>>> q = sectors(500)
>>> print q
None

>>> print sectors(500)
None

>>> print hello(2)
4








More information about the Python-list mailing list