"""File: to_roman2a.py Purpose: Convert a single character Roman numeral into a Hindu-Arabic numeral. Print a message if the character entered by the user isn't a legal Roman numeral, and exit. Run: python to_roman2a.py Input: Single character of a Roman numeral Output: Corresponding Hindu-Arabic numeral or error message """ from sys import exit #---------------------------------------------------------------------- def convert_to_number(roman_sym): """Convert a single character Roman numeral into a number """ if roman_sym == 'M': return 1000 elif roman_sym == 'D': return 500 elif roman_sym == 'C': return 100 elif roman_sym == 'L': return 50 elif roman_sym == 'X': return 10 elif roman_sym == 'V': return 5 elif roman_sym == 'I': return 1 else: print roman_sym, "isn't a valid Roman numeral!" exit() #---------------------------------------------------------------------- # Program starts here roman = raw_input("Enter a single character Roman numeral\n") number = convert_to_number(roman) print "The Roman numeral", roman, "corresponds to the" print " Hindu-Arabic numeral", number