fangsiyu 发表于 2021-12-20 16:43:42

用Python编写程序求1!+2!+……+7!

冬雪雪冬 发表于 2021-12-20 16:43:43

import math
print(sum(math.factorial(i) for i in range(1, 8)))

lucifinilhades 发表于 2021-12-20 21:09:31

fact = 1
fsum = fact
for n in range(2, 8):
        fact *= n
        fsum += fact
print(fsum)

roamcat 发表于 2021-12-20 21:54:22

a = 1
b = a
for n in range(2, 8):
      a = a * n
      b = b + a
print(b)

fangsiyu 发表于 2021-12-21 21:32:44

冬雪雪冬 发表于 2021-12-20 17:50


谢谢啊
页: [1]
查看完整版本: 用Python编写程序求1!+2!+……+7!