阶乘求和_

# 方法一
def sum(m, sum_result=0):
    if m == 0:
        return sum_result
    factorial = 1
    for i in range(1, m + 1):  # 这个循环可以计算m!
        factorial = factorial * i
    return sum(m - 1, sum_result + factorial)
print(sum(int(input())))


# 方法二
sums = 0
for i in range(1, int(input()) + 1):
    s = 1
    for j in range(1, i + 1):
        s = s * j
    # print(s)
    sums += s
print(sums)


# 方法三

print(sum([__import__('math').factorial(i) for i in range(1, int(input())+1)]))
# list= [math.factorial(i) for i in range(1, int(input()) + 1)]
# print(list)

上一篇:CSS OM


下一篇:花点时间把python入门<十八>——列表生成式的if/else问题