Ben Finney wrote:
> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > def add(x, y):
> > if x == 0:
> > print y
> > return y
> > else:
> > x -= 1
> > y += 1
> > add(x, y)
>
> To add to the other good advice in this thread:
>
> This is just one of many
In article <[EMAIL PROTECTED]>,
Ben Finney <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > def add(x, y):
> > if x == 0:
> > print y
> > return y
> > else:
> > x -= 1
> > y += 1
> > add(x, y)
...
> def recursive_add
On Nov 19, Ben Finney wrote:
...
> This is just one of many reasons why I advocate always having a
> *single* return statement, at the *end* of the function.
Agreed that it's a good *general* practice, but sometimes early exit
is useful and clear.
This is somewhat of a religious topic. A goo
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> def add(x, y):
> if x == 0:
> print y
> return y
> else:
> x -= 1
> y += 1
> add(x, y)
To add to the other good advice in this thread:
This is just one of many reasons why I advocate always having a
*si
[EMAIL PROTECTED] wrote:
> There is problaly a really simple answer to this, but why does this
> function print the correct result but return "None":
>
> def add(x, y):
> if x == 0:
> print y
> return y
> else:
> x -= 1
> y += 1
> add(x, y)
>
> prin
On 18 Nov 2005 06:30:58 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]
> wrote:> I still don't get it. I tried to test with x = 0 and found that to
Informative print statements can help you to see and understand
the program flow, especially if the problem is conceptual, with
no *real* errors in yo
[EMAIL PROTECTED] wrote:
> I still don't get it. I tried to test with x = 0 and found that to
> work. How come since the value of y is right and it is printed right it
> "turns into" None when returned by the return statement ?
because you're not returning the value to the print statement;
you're
[EMAIL PROTECTED] wrote:
> I still don't get it. I tried to test with x = 0 and found that to
> work. How come since the value of y is right and it is printed right it
> "turns into" None when returned by the return statement ?
Martin,
-a function should either return something or not. Your f
On 18 Nov 2005 06:30:58 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> I still don't get it. I tried to test with x = 0 and found that to
> work. How come since the value of y is right and it is printed right it
> "turns into" None when returned by the return statement ?
There is no return
I still don't get it. I tried to test with x = 0 and found that to
work. How come since the value of y is right and it is printed right it
"turns into" None when returned by the return statement ?
--
http://mail.python.org/mailman/listinfo/python-list
On 18 Nov 2005 05:22:47 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> There is problaly a really simple answer to this, but why does this
> function print the correct result but return "None":
>
> def add(x, y):
> if x == 0:
> print y
> return y
> else:
> x -
basically the other two points :-)
you create a string of add functions
add(2,4)--add(1,5)--add(0,6)
only in the last ( add(0,6) ) explicitly returns y, in the else of
add(1,5) you ignor it. If you want the starting add to return something
sensible you need to find a way to pass it back up the
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> There is problaly a really simple answer to this, but why does this
> function print the correct result but return "None":
>
> def add(x, y):
> if x == 0:
> print y
> return y
> else:
> x -= 1
> y += 1
>
any change you want to have :
"return add(x,y)" in the else ?
[EMAIL PROTECTED] wrote:
> There is problaly a really simple answer to this, but why does this
> function print the correct result but return "None":
>
> def add(x, y):
> if x == 0:
> print y
> return y
> else:
There is problaly a really simple answer to this, but why does this
function print the correct result but return "None":
def add(x, y):
if x == 0:
print y
return y
else:
x -= 1
y += 1
add(x, y)
print add(2, 4)
result:
6
None
Martin
--
http://mai
15 matches
Mail list logo