Generate a Fibonacci Series using Python
The Fibonacci Sequence
is the series of numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
The next number is
found by adding up the two numbers before it.
- The 2 is found by adding the two numbers before it
(1+1)
- The 3 is found by adding the two numbers before it
(1+2),
- And the 5 is (2+3),
- and so on!
Here is a longer list:
0, 1, 1, 2, 3, 5, 8, 13, 21,
34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711,
28657, 46368, 75025, 121393, 196418, 317811, ...
Fibonacci.py
def fib(n):
a=0
b=1
if n<=0:
print("enter
number above o")
elif n==1:
print(a)
else:
print(a)
print(b)
for i in range(2,n):
c= a+b
a = b
b =c
print(c)
fib(10)
|
0 Comments