forked from SushmitaY/mca101_2017
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.Addition.py
More file actions
43 lines (35 loc) · 1016 Bytes
/
6.Addition.py
File metadata and controls
43 lines (35 loc) · 1016 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
37
38
39
40
41
42
43
def increment(num):
'''
objective: to increment the value of a integer by 1
input parameters: num -> number to be incremented by one
return value: num + 1, successor of the given number
'''
'''
approach: using '+' operator to add 1 to the input number
'''
return num + 1
def mySum(num1, num2):
'''
objective: to find the sum of two numbers
parameters: num1 -> first non negative integer
num2 -> second non negative integer
return value: sum of num1 and num2
'''
'''
approach: using function increment() and using mySum() recursively
'''
assert num1 >= 0 and num2 >= 0
if num2 == 0:
return num1
else:
return mySum(increment(num1), num2 - 1)
#TEST CASES
a = 5
b = 8
print("\nSUM of ", a , " and ", b , " = " , mySum(a, b ))
a = 0
b = 56
print("\nSUM of ", a , " and ", b , " = " , mySum(a, b ))
a = 50
b = 0
print("\nSUM of ", a , " and ", b , " = " , mySum(a, b ))