Python提供的sum()函数可以接受一个list并求和,请编写一个prod()函数,可以接受一个list并利用reduce()求积:

def prod(a):
    def m(x,y):
        return x*y
    return reduce(m,a) #别忘了写return !
print(prod([3,5,7,9]))

if prod([3, 5, 7, 9]) == 945:
    print('测试成功!')
else:
    print('测试失败!')

猜你喜欢

转载自blog.csdn.net/qq_18287147/article/details/104394148
今日推荐