python中定义一个函数作为参数,为一个整数的N, 调用函数求得 1+2!+3!+...+n! 的和。(2!为2的阶乘)

解法一:单次循环
def num(n):
    i=1
    c=1
    h=0
    while i<=n:
        c*=i
        h+=c
        print(c)
        i+=1
    print(h)
num(n)
解法二:while双循环

def num(n):
    row=1
    h=0
    while row<=n:
        col=1
        l=1
        while col<=row:
            l*=col
            col+=1
        h +=l
        print(h)
        row+=1
num(n)

你可能感兴趣的:(python中定义一个函数作为参数,为一个整数的N, 调用函数求得 1+2!+3!+...+n! 的和。(2!为2的阶乘))