Skip to content

Instantly share code, notes, and snippets.

@pzp1997
Last active August 29, 2015 13:57
Show Gist options
  • Save pzp1997/9632988 to your computer and use it in GitHub Desktop.
Save pzp1997/9632988 to your computer and use it in GitHub Desktop.
import pdb
d = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}
while True:
num = input("Input a Roman Numeral to convert it to Arabic numbers: ")
if num.lower() == "quit" or num.lower() == "q":
break
total = 0
x = 0
while x < len(num)-1:
pdb.set_trace()
try:
if d[num[x]] > d[num[x+1]]:
total += d[num[x]]
else:
total += (d[num[x+1]] - d[num[x]])
x += 1
except KeyError:
print("Error: invalid entry.")
x = len(num)
x += 1
total += d[num[-1]]
print(num + ": " + str(total))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment