- Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathq37.py
29 lines (25 loc) · 664 Bytes
/
q37.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
# Python program to convert an integer to a roman numeral
classnum_to_rom:
defint_to_Rom(self, num):
val= [
1000, 900, 500, 400,
100, 90, 50, 40,
10, 9, 5, 4,
1
]
rom= [
"M", "CM", "D", "CD",
"C", "XC", "L", "XL",
"X", "IX", "V", "IV",
"I"
]
roman_num=''
i=0
whilenum>0:
for_inrange(num//val[i]):
roman_num+=rom[i]
num-=val[i]
i+=1
returnroman_num
print(num_to_rom().int_to_Rom(1))
print(num_to_rom().int_to_Rom(4000))