"""File: to_roman2.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. Run: python to_roman2.py Input: Single character of a Roman numeral Output: Corresponding Hindu-Arabic numeral or error message """ #---------------------------------------------------------------------- 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: return None #---------------------------------------------------------------------- # Program starts here roman = raw_input("Enter a single character Roman numeral\n") number = convert_to_number(roman) if number == None: print roman, "isn't a valid Roman numeral!" else: print "The Roman numeral", roman, "corresponds to the" print " Hindu-Arabic numeral", number