[docs] code bug in doc
rainbowsally at rainbowsally.org
Wed Aug 30 19:55:24 EDT 2017
In section "4.6. Defining Functions" on this page,
The code doesn't end with a newline and produces a syntax error due to
the >>> prompt at the end of the output.
Add another 'print' at the end to correct it.
>>>def fib(n): # write Fibonacci series up to n
... """Print a Fibonacci series up to n."""
... a, b = 0, 1
... while a < n:
... print a,
... a, b = b, a+b ... print ''
or something like that.
May also need a note to describe what the comma is doing in the "print
a" line. This comma isn't mentioned again until the Input and Output docs in
>>>for x in range(1, 11):
... print repr(x).rjust(2), repr(x*x).rjust(3),
... # Note trailing comma on previous line
... print repr(x*x*x).rjust(4)
But the function of the trailing comma is not explained there either.
Been holding off of learning a new programming language for quite a
while but I may just take the leap with Python this time.
More information about the docs