算定义的函数 ,调用 一次后,再次调用出错。为何。。
def rb(lista,listb,listc):
rb =['人本百分比',]
for i in range(1, 4):
try:
k = (lista+listb)/listc*100
rb.append('{:.2f}%'.format(k))
except:
rb.append('0')
return rb
x = ['社保费用', 28041.0, 27658.119999999974, 27398.559999999983]
y = ['工资', 408876.39999999997, 618590.6799999999, 660792.84]
z = ['销售额', 31707873.969999958, 33342556.38999991, 52047024.770000055]
rb = rb(x,y,z)
print(rb)
x1= ['社保费用', 56036.45, 42019.32999999998, 42772.16999999997]
y1= ['工资', 5899678.0130407475, 7400605.42, 9738936.469903704]
z1= ['销售额', 31707873.969999958, 33342556.38999991, 52047024.770000055]
rb1 = rb(x,y,z)
print(rb1)
结果如下:
['人本百分比', '1.38%', '1.94%', '1.32%']
Traceback (most recent call last):
File "C:/Users/handsome/Desktop/店铺导数据/rb.py", line 23, in <module>
rb1 = rb(x,y,z)
TypeError: 'list' object is not callable
>>>
17-18行rb = rb(x,y,z)
print(rb)改为print(rb(x,y,z))瞎赋值导致的严重后果。 拿函数名字作变量?
人才
页:
[1]