Skip to content

Commit aed25a6

Browse files
fixed ques3
1 parent b21e11b commit aed25a6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

_5/ques_3.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Factorial function to find factorial of a number
2+
def factorial(n):
3+
if n <= 1:
4+
return 1
5+
return n*factorial(n-1)
6+
7+
# Fibonacci function to find nth term of series
8+
def fib(n): #Recursive
9+
if n <= 0:
10+
return 0
11+
if n == 1:
12+
return 1
13+
return fib(n-1) + fib(n-2)
14+
15+
# def fib(n): #Iterative
16+
# pnum = 0
17+
# ppnum = 0
18+
# cnum = 1
19+
# for i in range(n):
20+
# ppnum = pnum
21+
# pnum = cnum
22+
# cnum = pnum + ppnum
23+
# return cnum
24+
25+
# Main
26+
if __name__ == "__main__":
27+
num = int(input("Enter a number: "))
28+
print("{}th term of fibonacci series: ".format(num), fib(num))
29+
print("Factorial of {}: ".format(num), factorial(num))

0 commit comments

Comments
 (0)