dict1 = {"CM":900, "D":500, "CD":400, "C":100, "XC":90, "L":50, "XL":40, "X":10, "IX":9, "V":5, "IV":4, "I":1} def roman2(num): final_string = "" remainder = num keys = iter(dict1.keys()) for i in range(len(dict1)//2): key1 = next(keys) value1 = dict1[key1] key2 = next(keys) value2 = dict1[key2] if remainder // value1 >= 1: final_string = final_string + key1 remainder = remainder % value1 elif remainder // value2 >= 1: final_string = final_string + key2 * (remainder // value2) remainder = remainder % value2 print(str(num) + "\t" + final_string) for i in range(1,1000): roman2(i)