forked from harshulmca17/MCA-101-_2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pred.py
48 lines (30 loc) · 987 Bytes
/
pred.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
40
41
42
43
44
45
46
47
48
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 pred(num,i = 0):
'''
Objective : To find predecessor of a given number
Input Parameters :
num : number of which predecessor needs to be found
Return Value : Predecessor of the given number
'''
#Approach: using function pred() reculsively
if num == 0:
return 0
if increment(i) == num:
return i
else:
i = increment(i)
i = pred(num,i)
return i
def main():
num= int(input("Enter a number: "))
print("Predecessor of the number: ",pred(num))
if __name__ == '__main__':
main()