+2 votes
in Programming Languages by (74.2k points)

Can I get a python code for the Fibonacci numbers up to a value 'N'?

1 Answer

+1 vote
by (351k points)
selected by
 
Best answer

Here is the python code for the Fibonacci numbers up to a value 'N'?

# Fibonacci numbers up to n
def fibonacciNumbersUptoN(n):
    nums = []
    a, b = 0, 1
    while a < n:
        nums.append(a)
        a, b = b, a + b
    return nums

if __name__ == "__main__":
    print(fibonacciNumbersUptoN(1000))
 

The above code will output the following numbers:

[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]


...