-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ12.py
More file actions
22 lines (19 loc) · 743 Bytes
/
Q12.py
File metadata and controls
22 lines (19 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'''12. Write a program in python to create a recursive function to calculate the
Fibonacci number of a specific term.
Test Data :
Enter a number: 10
Expected Output :
The Fibonacci of 10 th term is 55'''
def fibonacci():
n = int(input("Enter the term number for Fibonacci sequence: "))
def fib(n):
if n <= 0:
return 0
elif n == 1:
return 1
else:
return fib(n - 1) + fib(n - 2)
result = fib(n)
print(f"The Fibonacci of {n}th term is {result}."), print("The sequence starts with 0 and 1, and each subsequent number is the sum of the two preceding ones: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...")
#call the function to execute
fibonacci()