Answer the question
In order to leave comments, you need to log in
Why doesn't the POW function (Python) work correctly?
I have a VBS code and need to translate it to Python 2.7 (used in calculating "Effective APR" ):
wscript.echo 1.5^(-1/12) '0.966775705727066
wscript.echo 1.5^(-2/12) '0.934655265184067
wscript.echo 1.5^(-3/12) '0.903602003609845
wscript.echo 1.5^(-4/12) '0.873580464736299
wscript.echo 1.5^(-5/12) '0.844556370304814
wscript.echo 1.5^(-6/12) '0.816496580927726
wscript.echo 1.5^(-7/12) '0.789369058250139
wscript.echo 1.5^(-8/12) '0.763142828368888
print pow(1.5, -1/12) # 0.6666666666666666
print pow(1.5, -2/12) # 0.6666666666666666
print pow(1.5, -3/12) # 0.6666666666666666
print pow(1.5, -4/12) # 0.6666666666666666
print pow(1.5, -5/12) # 0.6666666666666666
print pow(1.5, -6/12) # 0.6666666666666666
print pow(1.5, -7/12) # 0.6666666666666666
print pow(1.5, -8/12) # 0.6666666666666666
Answer the question
In order to leave comments, you need to log in
python 2, unlike python 3, works with int when dividing.
Add
to the top of your code
Either, you can do this:
from __future__ import division
print pow(1.5, -1/float(12))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question