因子不输出整数

Use*_*er1 0 python

我不是一个非常有经验的程序员,但我只是用Python编写这个来尝试查找e,使用的定义e是1/0的总和!+ 1/1!+ 1/2!等等...

我遇到的问题是def factorial不输出整数.我意识到它不会给它如何写,但我不知道我怎么能做到.total是我想要输出的int def factorial.

e = 0

def factorial(m):
    n = m - 1
    total = 1
    if n > 0:
        total = m
    while n > 0:
        total = total * n
        n = n - 1

for w in range(0,100):
    s = factorial(w)
    e = e + ( 1 / s )

print(e)
Run Code Online (Sandbox Code Playgroud)

hat*_*rby 6

def factorial(m):
    n = m - 1
    total = 1
    if n > 0:
        total = m
    while n > 0:
        total = total * n
        n = n - 1
    return total
Run Code Online (Sandbox Code Playgroud)

编辑:问题是,为了从中获取信息factorial,您必须使用return语句.return评估后的任何内容,并用作sin 的值s = factorial(w).