我对编程和学习Python非常陌生。我试图编写一个简单的代码,将整数转换为罗马数字。我正在寻找一种方法,将我创建的列表转换为类似MCCVI的内容。现在,如果整数exp。1523是像MDXXIII一样写的。这是我的代码:
a= int(input("Geben sie eine Zahl ein:"))
M=1000
D=500
C=100
L=50
X=10
V=5
I=1
liste= ["M","D","C","L","X","V","I"]
i=0
erg=[]
while i < len(liste):
while a > eval(liste[i]):
a = a- eval(liste[i])
erg += liste[i]
i+=1
print(erg)发布于 2016-11-03 19:05:12
a= int(input("Geben sie eine Zahl ein:"))
roman_map = [(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')]
roman_num = ""
while a > 0:
for i, r in roman_map:
while a >= i:
roman_num += r
a -= i
print romanhttps://stackoverflow.com/questions/40409279
复制相似问题