作业
Topic source为什么你的代码可以测试成功?x是必须的参数,直接Product()传空不是应该异常才对吗?
def product(*args): if not args: raise TypeError('参数为空') r = 1 for i in args: r = r * i return r
- 1
为什么你的代码可以测试成功?x是必须的参数,直接Product()传空不是应该异常才对吗?
def product(*args): if not args: raise TypeError('参数为空') r = 1 for i in args: r = r * i return r
琪琪妈妈0512
def product(x,*args):
for n in args:
x=x*n
return x
运行结果:
product(5) = 5
product(5, 6) = 30
product(5, 6, 7) = 210
product(5, 6, 7, 9) = 1890
测试成功!