Created
December 17, 2010 05:48
-
-
Save bensonk/744542 to your computer and use it in GitHub Desktop.
Roman Numerals
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
| 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