python运行脚本时提示TypeError: float argument required, not str这个错误,有大佬知道原因吗,望解答

图片说明

图片说明

在cmd上运行时出现了这个错误,

Traceback (most recent call last):
File "F:\python_code\total", line 19, in
print('%s同学编程投入资金%f元。'%(counts[i],counts[i+1]))
TypeError: must be real number, not str

然后我在linux虚拟机上的python运行也是类似情况

Traceback (most recent call last):
File "./total.py", line 20, in
print('%s同学编程投入资金%f元'%(counts[i],counts[i+1]))
TypeError: float argument required, not str

我在windows上安装的python是3.7版本
虚拟机上linux的python是2.6.6版本

上面问题希望有大佬帮忙看一下,萌新小白,实在是不懂哪里出问题了

图片说明

现在报错是因为这个你的total +counts[i+1]; counts[i+1]是一个数组,你用一个整数去加一个数组是会报错的,建议你把counts打印出来看下你就明白了

for 循环语句块的第二行要缩进啊,不缩进你的counts的内容是不对的

你的第15行没有缩进,19行改成print('%s同学编程投入资金%d元。'%(counts[i],counts[i+1]))