【发布时间】:2017-03-18 05:44:18
【问题描述】:
我爬网但没有答案(特定于解决方案)。我遇到了以下问题:
coin = [2.0 , 1.0 , 0.5, 0.1, 0.05, 0.02, 0.01]
kum=0.0
for i in coin :
while True :
if kum + coin[i] >= x :
# Intial (first loop) this should be equal to: if 0 + 2.0 > users input
# Second loop should be equal to if 2.0 + 1.0 > users input
break
else :
kum += coin[i]
控制台说:
Traceback (most recent call last):
, line 13, in <module>
if kum + coin[i] >= x :
TypeError: list indices must be integers, not float
我想知道我做错了什么。 列表项是浮动的?添加 0.0 和 float 应该不是问题吗? 任何帮助表示赞赏。 `
【问题讨论】:
标签: python arrays integer indices