ln (Natural Log) in Python

本小妞迷上赌 提交于 2019-12-07 06:33:45

问题


In this assignment I have completed all the problems except this one. I have to create a python script to solve an equation (screenshot).

Unfortunately, in my research all over the internet I cannot figure out how in the world to either convert ln to log or anything usable, or anything. The code I have written so far is below. I will also post the answer that our teacher says we should get.

import math
p = 100
r = 0.06 / 12
FV = 4000

n = str(ln * ((1 + (FV * r) / p) / (ln * (1 + r))))

print ("Number of periods = " + str(n))

The answer I should get is 36.55539635919235 Any advice or help you have would be greatly appreciated!

Also, we are not using numpy. I already attempted that one.

Thanks!


回答1:


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:

n = math.log((1 + (FV * r) / p) / math.log(1 + r)))

Note that in your code you convert n to a str twice which is unnecessary



来源:https://stackoverflow.com/questions/39235906/ln-natural-log-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!