forked from SheenamYadav/mca101_vidul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
increment.py
40 lines (37 loc) · 839 Bytes
/
increment.py
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
37
38
39
def increment(n):
n=n+1
return n
def add(num1,num2):
if num2<0:
return add(num1-1,increment(num2))
elif num2==0:
return num1
else:
return add(increment(num1),num2-1)
def pred(num,i=-25):
if num==1:
return 0
else:
x=increment(i)
if x==num:
return i
else:
return pred(num,increment(i))
def multiply(num1,num2):
if num2==0:
return 0
else :
return num1+multiply(num1,num2-1)
def subtract(num1,num2):
if num2<0:
return subtract(increment(num1),increment(num2))
elif num2==0:
return num1
else:
return subtract(pred(num1),pred(num2))
def divide(num1,num2,i=0):
if num1<num2:
return i
else:
i=i+1
return divide(subtract(num1,num2),num2,i)