python-core-50,第20课发现错误
ksi1110 opened this issue · comments
Nathan commented
def calc(*args, **kwargs):
result = 0
for arg in args:
result += arg
for value in kwargs.values():
result += value
### return total
最后应该是return result
Nathan commented
函数使用进阶,高阶函数,发现代码位置错误
import operator
print(calc(init_value=0, op=operator.add, 1, 2, 3, x=4, y=5)) # 15
print(calc(init_value=1, op=operator.mul, 1, 2, x=3, y=4, z=5)) # 120
位置参数应该写在关键字参数前面,正确代码为:
print(calc(1, 2, 3, init_value=0, op=operator.add, x=4, y=5))
或者
print(calc(1, 2, x=3, y=4, z=5, init_value=1, op=operator.mul))
ajian commented
i also find out this mistake,please change it