Why is a None appearing in my output?
Hugh Macdonald
HughMacdonald at brokenpipefilms.com
Wed May 12 16:08:44 EDT 2004
----- Original Message -----
From: "David Stockwell" <winexpert at hotmail.com>
To: <python-list at python.org>
Sent: Wednesday, May 12, 2004 8:46 PM
Subject: Why is a None appearing in my output?
> I entered the following text into a 'module file' and saved it:
>
> def fib6(n): # write Fibonacci series up to n
> a, b = 0, 1
> while b < n:
> print b,
> a, b = b, a+b
> else:
> print "done b[",b,"], n[",n,"], a[", a,"]"
>
> print "fib6:", fib6(50), "---"
> print "next"
What it's doing is this:
print "fib6:",
run fib6(50)
print b various times
print "done b[",b,"], n[",n,"], a[", a,"]"
print what was returned from fib6(50) (in this case None)
print "---"
print "next"
Your best bet would be to change the line:
print "fib6:", fib6(50), "---"
to
print "fib6:",
fib6(50),
print "---"
OR change the function itself to:
def fib6(n): # write Fibonacci series up to n
a, b = 0, 1
while b < n:
print b,
a, b = b, a+b
return "done b[",b,"], n[",n,"], a[", a,"]"
Hugh Macdonald
More information about the Python-list
mailing list