Elim Qiu on Sat, 16 Sep 2017 16:54:47 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

how to define a function with loop


I'd like to define a function returns the decimal approximation of

(1^n+2^n+...+n^n)/(n^n)

In python i have

def tm(n,k):
    return exp(n*log((k+0.0)/n))

def sm(n,m):
    s = 0.0
    for j in range(m):
        k = n -j
        s += tm(n,k)
    return s

How do I put a loop inside of a definition of pari function?

Thanks