DSA/algorithms/Python/strings/int-to-roman.py

23 lines
479 B
Python
Raw Normal View History

2023-06-21 21:50:10 +00:00
'''
Output the correct Roman numerals for a given number.
Input: 1994
Output: MCMXCIV
MDCD
Time Complexity: ???
Space Complexity: ???
'''
def int_to_roman(num):
reference = [("M", 1000), ("CM", 900), ("D", 500), ("CD", 400), ("C", 100), ("XC", 90), ("L", 50), ("XL", 40), ("X", 10), ("IX", 9), ("V", 5), ("IV", 4), ("I", 1)]
for numeral in range(len(reference)):
if numeral[1]:
...
if __name__ == "__main__":
print(int_to_roman(1994))
# MCMXCIV