-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibnacci.py
More file actions
42 lines (34 loc) · 862 Bytes
/
fibnacci.py
File metadata and controls
42 lines (34 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
n=int(input(" enter no. of elements in your fibnacci series "))
def fibnacci(n):
a=0
b=1
if n<=0:
print(" enter a valid number which is greater than 0 ")
elif n==1:
print(a)
else:
print(a,b , end=" ")
for i in range(2,n):
c=a+b
a=b
b=c
print(c, end= " ")
fibnacci(n)
""" if we want series tiil user specified number """
n=int(input(" enter no. of elements in your fibnacci series "))
def fibnacci(n):
a=0
b=1
if n<=0:
print(" enter a valid number which is greater than 0 ")
elif n==1:
print(a)
else:
print(a,b , end=" ")
for i in range(2,n):
c=a+b
a=b
b=c
if n>=c:
print(c, end= " ")
fibnacci(n)