-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactorial.py
More file actions
38 lines (30 loc) · 823 Bytes
/
Factorial.py
File metadata and controls
38 lines (30 loc) · 823 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
# This program calculates the factorial of the input number using recursion including explanation.
def fact(n):
if n == 1:
return n
else:
# recursion
return n*fact(n-1)
num = int(input("Enter a whole number to find Factorial: "))
if num < 0:
print("Factorial can’t be calculated for negative number")
elif num == 0:
print("Factorial of 0 is 1")
else:
print("Factorial of", num, "is", fact(num))
class Test:
def __init__(self, x):
self.a = x
def get_data(self):
print('some code to fetch data from databas')
def f1(self):
self.get_data()
def f2(self):
self.get_data()
t1 = Test(5)
t1.f2()
t1.f1()
def new_get_data(self):
print("Some code to fetch data from test")
Test.get_data = new_get_data
print("After monkey patching ")