numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(sum(numbers))
from functools import reduce
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
results = reduce(lambda x, y: x + y, numbers)
print(results)
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
result = 0
for number in numbers:
result += number
print(result)
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def cal(list1, size):
if size:
return list1[size - 1] + cal(list1, size - 1)
return size
print(cal(numbers, len(numbers)))
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
from functools import reduce
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
results = reduce(lambda x, y: x * y, numbers)
print(results)
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def cal(list1, size):
if size == 0:
return 1
return list1[size - 1] * cal(list1, size - 1)
print(cal(numbers, len(numbers)))
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
result = 1
for number in numbers:
result *= number
print(result)
原文:https://www.cnblogs.com/wxhou/p/14113774.html