我用 for 循环写了这个等式。有人知道其他形式来写这个等式吗?

I have written this equation with for loop. anyone got any idea about other forms to write this equation?

等式:1 + 1/2! + 1/3! + 1/4! ... + 1/n! --> (n < 10)

#define factorial

def fact(x):
    if x == 0:
        return 1
    else:
        return x * fact(x-1)

#------------路漫漫其修远兮------------

#equation= 1 + 1/fact(2) + 1/fact(3) + 1/fact(4) + 1/fact(5) + 1/fact(6)+ 1/fact(7) + 
#1/fact(8)+ 1/fact(9) 
#print(equation)

#--------带for循环------

s = 1
for x in range (2,10) :
  s += (1/fact(x))
print(s)
 

#----------------------------

一种方法是使用 math.fact

import math
s = 1
for x in range (2,10) :
  s += (1/math.fact(x))
print(s)

如果它总是 n < 10,那为什么每次都计算阶乘,

s = 1
y = 9*8*7*6*5*4*3*2
j = 9
while j >1:
  s += (1/y)
  y = y/j
  j = j-1
print(s)

或者仅计算第 n 个数的阶乘,并执行与上述相同的操作。