1
1
# Write a program to convert interger to Roman Representation
2
- def convertIntegerToRomanNum (inputNumber ):
2
+ def convertIntegerToRomanNum (input_num ):
3
3
4
4
number_list = [
5
5
1000 , 900 , 500 , 400 ,
@@ -18,12 +18,35 @@ def convertIntegerToRomanNum(inputNumber):
18
18
result_str = ''
19
19
i = 0
20
20
21
- while inputNumber > 0 :
22
- for _ in range (inputNumber // number_list [i ]):
21
+ while input_num > 0 :
22
+ # if input_num//number_list[i] > 0 , then we will get a string appended
23
+ # else it will continue the loop
24
+ for _ in range (input_num // number_list [i ]):
23
25
result_str = result_str + symbol_list [i ]
24
- inputNumber = inputNumber - number_list [i ]
26
+ input_num = input_num - number_list [i ]
25
27
i = i + 1
26
28
return result_str
27
29
28
30
roman = convertIntegerToRomanNum (289 )
29
31
print (roman )
32
+
33
+ # ===============
34
+ # Explaination:
35
+ # ===============
36
+ # 289
37
+ # 289//1000 --> 0, i=1
38
+ # 289//900 --> 0, i=2
39
+ # 289//500 --> 0, i=3
40
+ # 289//400 --> 0, i=4
41
+ # 289//100 --> 2, then i=4, result_str = 'C', input_num = 189
42
+ # 198//100 --> 1, then i=4, result_str='CC', input_num = 89
43
+ # 98//100 --> 0, then i=5
44
+ # 98//50 --> 1, then i=6, result_str='CCL', input_num= 39
45
+ # 39//50 --> 0, then i=6
46
+ # 39//40 --> 0, then i=7
47
+ # 39//10 --> 3, then i=8, result_str='CCLX', input_num=29
48
+ # 29//10 --> 3, then i=8, result_str='CCLXX', input_num=19
49
+ # 19//10 --> 3, then i=8, result_str='CCLXXX', input_num=9
50
+ # 9//10 --> 0, then i=9
51
+ # 9//9 --> 1, then i=9, result_str='CCLXXXIX', input_num=0
52
+ # EXIT
0 commit comments