Last active
August 29, 2015 13:57
-
-
Save pzp1997/9632988 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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