-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroman.py
More file actions
89 lines (77 loc) · 1.12 KB
/
Copy pathroman.py
File metadata and controls
89 lines (77 loc) · 1.12 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#
# roman numbers can u believe it?
# @spiralbend 2025-07-06
#
import sys
log = 0
def main():
if len(sys.argv) > 1:
num = int(sys.argv[1])
else:
num = int(input("Number to convert: "))
arabic = str(num)
log = len(arabic) - 1
answer = ""
for digit in arabic:
answer += convert(digit, log)
log -= 1
print(answer)
def convert(n, place):
base = int(10**place)
rdig = roman[base] * int(n)
# if len(rdig) == 1
roman = {
1000: "M",
900: "CM",
500: "D",
400: "CD",
100: "C",
90: "XC",
50: "L",
40: "XL",
10: "X",
9: "IX",
5: "V",
4: "IV",
1: "I",
}
rnum = {
3: "M",
2: [
"",
"C",
"C",
"C",
"CD",
"D",
"C",
"C",
"C",
"CM",
],
1: [
"",
"X",
"X",
"X",
"XL",
"L",
"X",
"X",
"X",
"XC",
],
0: [
"",
"I",
"I",
"I",
"IV",
"V",
"I",
"I",
"I",
"IX",
],
}
main()