交作业
Topic sourcedef product(numbers): if len(numbers) < 1: raise TypeError('参数缺失') res = None for i in numbers: if not isinstance(i, (int, float)): raise TypeError('参数中能为数字') if res == None: res = i else: res = i return res
def product(*numbers): if len(numbers) < 1: raise TypeError('参数缺失') res = None for i in numbers: if not isinstance(i, (int, float)): raise TypeError('参数中能为数字') if res == None: res = i else: res = i return res
我发现用了两个**才能正常显示出来
- 1
keepmoving9
def product(x): sum=1 for n in x: sum=sumn print (sum) print ('请输入需要计算乘积的因数:') lst = [] #定义一个空列表
str = input("请输入数值,用空格隔开:")
lst1 = str.split()#lst1用来存储输入的字符串,用空格分割
i = 0
n=int(len(lst1)) print (n) while i <= n-1:
lst.append(int(lst1.pop()))#将lst1的数据转换为整型并赋值给lst
i += 1
print (lst) #打印已转换为整数的数据列表 product(*lst) #调用自定义函数