2nd Year 2nd Assignment in Python Programming
2nd Year 2nd Assignment in Python Programming
Q:- write a programme in python to input number and find Fibonacci series using recursion.
#Python programme to input number and find Fibonacci series using recursion.
#Algorithm
1. Initialize an array arr of size n to zeros.
2. If n equals 0 or 1; return 1 Else.
3. Initalize arr[0] and arr[1] to 1.
4. Run for loop in range[2,num]
5. Compute the value arr[I]=arr[I-1] +arr[I-2]
6. The array has the sequence computed till n.
#flowchart
Program:-
def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
Programming class assignment -2
Name :-lovekush kumar # roll no:-27600120018 #sec :-A
# take input from the user
nterms = int(input("How many terms? "))
# check if the number of terms is valid
if nterms <= 0:
print("Plese enter a positive integer")
else:
print("Fibonacci sequence:")
for i in range(nterms):
print(recur_fibo(i))
input:-
How many terms? 10
output:
== RESTART: D:\loveraj\love\love programming\python programming\-----recur.py ==
Fibonacci sequence:
13
21
34
>>>
Programming class assignment -2
Name :-lovekush kumar # roll no:-27600120018 #sec :-A