We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b21e11b commit aed25a6Copy full SHA for aed25a6
_5/ques_3.py
@@ -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
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