MCPcopy Create free account
hub / github.com/geekcomputers/Python / fib

Function fib

primelib/primelib.py:616–634  ·  view source on GitHub ↗

input: positive integer 'n' returns the n-th fibonacci term , indexing by 0

(n)

Source from the content-addressed store, hash-verified

614
615
616def fib(n):
617 """
618 input: positive integer 'n'
619 returns the n-th fibonacci term , indexing by 0
620 """
621
622 # precondition
623 assert isinstance(n, int) and (n >= 0), "'n' must been an int and >= 0"
624
625 tmp = 0
626 fib1 = 1
627 ans = 1 # this will be return
628
629 for i in range(n - 1):
630 tmp = ans
631 ans += fib1
632 fib1 = tmp
633
634 return ans

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected