+ 6
Number Conversion Challenge
Write a program to take a no. n and convert it into roman numerals. for eg. input : 15 output : XV
5 ответов
+ 6
Nice idea. Wait, I am groggy from waking up.
+ 3
lets try....
+ 3
I have made it. But the program is quite large.
https://code.sololearn.com/cwISOQ76jLp3/?ref=app
+ 2
UPD: Fix bags:
https://code.sololearn.com/cLEWeFZtSVN8/?ref=app
+ 1
romans = [(1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"), (90, "XC"),
(50, "L"), (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I")]
def convert_to_roman(num):
out = ""
for a, b in romans:
q, num = divmod(num, a)
out += q*b
return out
user_input = int(input("Enter a number to convert to Roman Numeral: "))
print()
print(convert_to_roman(user_input))