Question: python , use iteration The Fibonacci sequence is a famous sequence in mathematics. The first element in the sequence is 0 and the second element

python , use iteration

The Fibonacci sequence is a famous sequence in mathematics. The first element in the sequence is 0 and the second element is 1. The nth element is defined as Fn = Fn-1 + Fn-2.

Implement the fib function, which takes an integer n and returns the nth Fibonacci number. Use a while loop in your solution.

def fib(n):

"""Returns the nth Fibonacci number.

>>> fib(0)

0

>>> fib(1)

1

>>> fib(2)

1

>>> fib(3)

2

>>> fib(4)

3

>>> fib(5)

5

>>> fib(6)

8

>>> fib(100)

354224848179261915075

""" "*** YOUR CODE HERE ***"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!