-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathroman_number.py
More file actions
34 lines (28 loc) · 730 Bytes
/
roman_number.py
File metadata and controls
34 lines (28 loc) · 730 Bytes
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
# This code is made by MRayan Asim
tallies = {
"I": 1,
"V": 5,
"X": 10,
"L": 50,
"C": 100,
"D": 500,
"M": 1000,
# add more numerals if necessary
}
def RomanNumeralToDecimal(romanNumeral):
sum = 0
for i in range(len(romanNumeral) - 1):
left = romanNumeral[i]
right = romanNumeral[i + 1]
if tallies[left] < tallies[right]:
sum -= tallies[left]
else:
sum += tallies[left]
sum += tallies[romanNumeral[-1]]
return sum
# Get user input
roman_numeral = input("Enter a Roman numeral: ")
# Convert to decimal
decimal_numeral = RomanNumeralToDecimal(roman_numeral)
# Print the result
print("Decimal equivalent:", decimal_numeral)