Search code examples
pythonmathnotation

For loop to math notation


Can someone tell me how can I write the following in math notation

for x in (range(1,n)):
    var1=1
    var2=0

    var1*=x
    var2+=x
    
    Var3+=var1/var2

I tried SUM((n!)/SUM(n) but I cant seem to get the same answer.

Thank you in advance.

Update: I apologize to everyone I deceived, I just didn't want help in trying to generate an original formula for factorials because for me it was the ultimate challenge and fun. The idea was to use the fact that the below resulted in an approximation for e to find a way to solve for n! only issue is I was too naive to think that the formula for Sum applied towards Fractions... Forgive me community you are AWESOME!!!

I also adjusted this a bit from the previous one.

($\sum_{i=0}^n \frac{\sum_{i=0}^n n}{n!} $)*(3/2 -1/10**N)

num=100
var1=0
var2=1
e8= 0

for x in (range(1,num)):
    var1+=x
    var2*=x
    e8+=var1/var2

Sym=(3/2 -(1/10**num))

e8*=1/Sym
print(Sym)


print(e8) 

Solution

  • Upon exit of the loop and assuming that Var3 is initialized to 0, Var3 will equal n-1. (I bet this is not what you expect.)


    If one moves the (re-)initializations out of the loop, the formula is

    enter image description here