-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathromanizer.py
51 lines (50 loc) · 1.05 KB
/
romanizer.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
49
50
51
import sys,os
def romanizer(numbers):
result = []
for num in numbers:
curr_roman = helper(num)
result.append(curr_roman)
return result
def helper(num):
res = ''
while num>0:
if num-1000>=0:
res+='M'
num-=1000
elif num-900>=0:
res+='CM'
num-=900
elif num-500>=0:
res+='D'
num-=500
elif num-400>=0:
res+='CD'
num-=400
elif num-100>=0:
res+='C'
num-=100
elif num-90>=0:
res+='XC'
num-=90
elif num-50>=0:
res+='L'
num-=50
elif num-40>=0:
res+='XL'
num-=40
elif num-10>=0:
res+='X'
num-=10
elif num-9>=0:
res+='IX'
num-=9
elif num-5>=0:
res+='V'
num-=5
elif num-4>=0:
res+='IV'
num-=4
elif num-1>=0:
res+='I'
num-=1
return res