# Roman2.py # Author: Hyung-Joon Kim # CSE, University of Washington def Roman2(x): # Roman numeral conversion with ordered Production System ans = '' while True: if x > 3999: return 'The number is too big.'; elif x > 999: ans += 'M'; x -= 1000 elif x > 899: ans += 'CM'; x -= 900 elif x > 499: ans += 'D'; x -= 500 elif x > 399: ans += 'CD'; x -= 400 elif x > 99: ans += 'C'; x -= 100 elif x > 89: ans += 'XC'; x -= 90 elif x > 49: ans += 'L'; x -= 50 elif x > 39: ans += 'XL'; x -= 40 elif x > 9: ans += 'X'; x -= 10 elif x == 9: ans += 'IX'; x = 0 elif x > 4: ans += 'V'; x -= 5 elif x == 4: ans += 'IV'; x = 0 elif x > 0: ans += 'I'; x -= 1 elif x == 0: return "The converted Roman numeral : " + ans; else: return 'bad number'; break