Skip to content

Instantly share code, notes, and snippets.

@bensonk
Created December 17, 2010 05:48
Show Gist options
  • Select an option

  • Save bensonk/744542 to your computer and use it in GitHub Desktop.

Select an option

Save bensonk/744542 to your computer and use it in GitHub Desktop.
Roman Numerals
vals = { "I" : 1, "V" : 5, "X" : 10, "L" : 50, "C" : 100, "D" : 500, "M" : 1000, "_" : 0}
while True:
input = raw_input("Enter a roman numeral: ").upper()
if input == "QUIT": break
input = [ vals[v] for v in input if v in vals ]
value = 0
for cur, next in zip(input, (input+[0])[1:]):
if cur >= next: value += cur
else: value -= cur
print "Value: %d" % value
print "Goodbye."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment