def product(*nums):
if len(nums)==0:
raise TypeError('empty input,pls re-input')
s = 1
for n in nums:
if not isinstance(n,(int,float)):
raise TypeError('input data is not int or float data')
s = s*n
return s
测试条件里,有空输入的时候怎么办?编制练习程序地时候不要忘了。
Sign in to make a reply
有为若是
def product(*nums):
if len(nums)==0:
raise TypeError('empty input,pls re-input')
s = 1
for n in nums:
if not isinstance(n,(int,float)):
raise TypeError('input data is not int or float data')
s = s*n
return s