E
E
Emil Revencu2020-06-28 22:44:17
Python
Emil Revencu, 2020-06-28 22:44:17

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


But in Python, I have very different meanings:
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

Where is the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-06-28
@Revencu

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))

E
Emil Revencu, 2020-06-28
@Revencu

Ah... I found a mistake: thank
you all
print pow(1.5, -1.0/12)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question