这是一个代码挑战,您必须返回给定参数的总和。所有参数的总和
说明:
Calculate the sum of all the arguments passed to a function.
Note: If any of the arguments is not a finite number the function should return false/False instead of the sum of the arguments.
这里是我的代码:
def sum_all(*args):
sum = 0
for str(num) in args:
if not num.isdigit():
return False
else:
int(sum) += num
return sum
目前我得到这个错误:
File "", line 9
SyntaxError: can't assign to function call
在'Test.assert_equals(sum_all。。 (76856,-32,1981,1076),79881)',我得到的错误:'假应等于79881' –
哦,你只要让我意识到这是如何简化更新 – idjaw
这工作,但你可以简单。!向我解释为什么这个解决方案的作品相比,旧的解决方案? –