ln (Natural Log) in Python

math.log is the natural logarithm: From the documentation: math.log(x[, base]) With one argument, return the natural logarithm of x (to base e). Your equation is therefore: Note that in your code you convert n to a str twice which is unnecessary