so first all we have to know what is a fibonacci series , in this next element is the sum of present element and the previous element
for ex:
0, 1, 1, 2, 3, 5, 8, 13, .................................so on
a b c
we can say a and b are the previous and the number and c is the sum i.e output
code:
def fib(n) # func declaration
a = 0 # declaration of a and b
b = 1
print(a, b, end = " , ") # by use of "end" it displays numbers horizontally
for i in range(2,n):
c = a + b
a = b
b = c
print(c, end= " ,")
fib(10) # calling function
assignment :
Q: if argument passed i.e n is 100 then it should print only till 89
i.e
-> fib(100)
output
0 ,1,1,2 3, 5, 8,13,21, 34, 55, 89
Thank you do subscribe and follow
and ask any question
for ex:
0, 1, 1, 2, 3, 5, 8, 13, .................................so on
a b c
we can say a and b are the previous and the number and c is the sum i.e output
code:
def fib(n) # func declaration
a = 0 # declaration of a and b
b = 1
print(a, b, end = " , ") # by use of "end" it displays numbers horizontally
for i in range(2,n):
c = a + b
a = b
b = c
print(c, end= " ,")
fib(10) # calling function
OUTPUT:
assignment :
Q: if argument passed i.e n is 100 then it should print only till 89
i.e
-> fib(100)
output
0 ,1,1,2 3, 5, 8,13,21, 34, 55, 89
Thank you do subscribe and follow
and ask any question

Comments
Post a Comment