Discuss / Python / 作业第二题

作业第二题

Topic source

l=input('输入数字') ll=l.split(",") ll= [int(ll[i]) for i in range(len(ll))]#将键盘输入的数字转换为list,注意每个元素的数据类型

def prod(x,y): return x*y
p=reduce(prod,ll) #定义函数prod,使用reduce方法返回ll中的第一个到第n个数字的乘积 print('这几个数字的乘积为',p) #输出返回结果


  • 1

Reply