-3
我看下面的代碼,但我需要其他的方式來代替以下元素:我可以用什麼來代替?
- =和。加入(結果)。
def int_to_roman(input):
if not isinstance(input, type(1)):
raise TypeError("expected integer, got %s" % type(input))
if not 0 < input < 4000:
raise ValueError("Argument must be between 1 and 3999")
ints = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)
nums = ('M', 'CM', 'D', 'CD','C', 'XC','L','XL','X','IX','V','IV','I')
result = []
for i in range(len(ints)):
count = int(input/ints[i])
result.append(nums[i] * count)
input -= ints[i] * count
return ''.join(result)
謝謝
你是什麼實際問題? – brittenb
請注意,使用輸入作爲變量是一個壞主意,因爲輸入是一個內置的,但你有更大的問題(如實際上有一個可回答的問題)首先 – Foon