fibonacci specific number generator python

Raau :

Is there a way on how to only show the Nth number? e.g. I want the 15th Fibonacci Number, but this only gives lists.

a = int(input('Enter N Number: '))

def fib(n):
    a = b = 1
    for i in range(n):
        yield a
        a, b = b, a + b

print(fib(a))
AK47 :

Convert the result of fib() to a list and index it at -1:

print(list(fib(a))[-1])

>> Enter N Number: 15
>> [610]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=193937&siteId=1