Skip to content

4.8. Defining Functions example is slightly misleading #125383

@gitstashgithub

Description

@gitstashgithub

https://docs.python.org/3/tutorial/controlflow.html#defining-functions
This is the example:

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, end=' ')
        a, b = b, a+b
    print()

# Now call the function we just defined:
fib(2000)

But this example writes Fibonacci series less than n, not up to n.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc direasy

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions