Discuss / Python / 第二题

第二题

Topic source
from functools import reduce
def prod(l):
    def f(x,y):
        return x*y
    return reduce(f,l)
#测试
print('3 * 5 * 7 * 9 =', prod([3, 5, 7, 9]))
if prod([3, 5, 7, 9]) == 945:
    print('测试成功!')
else:
    print('测试失败!')

  • 1

Reply