Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 15 Online
OpenStudy (anonymous):

Hey, I'm doing problem set 2. The writer decided that "annualInterestRate / 12" is what the monthly rate should be! However, in order to be accurate the monthly rate is the twelfth root of annual rate. So, that leads to my question. When I type "monthlyRate = math.pow(1.18,1/12)" and then "print monthlyRate" it prints "1.0" How do I ask Python to calculate the twelfth root to at lest 4 decimal places?

OpenStudy (anonymous):

It's doing integer division on 1/12 and resolving that to 0, and anything to the power of zero is one. What you need is to have the 1/12 resolved with floating point division so you actually get a fraction ... use 1.0/12.0 instead (make both the numerator and denominator have a decimal in them to force the floating point division) >>> math.pow(1.18, 1.0/12.0) >>> 1.0138884303484099 One way to print it out with four decimal point precision is: >>> "%.4f" % math.pow(1.18, 1.0/12.0) >>> '1.0139'

OpenStudy (anonymous):

or you could use round(math.pow(1.18, 1.0/12.0),4)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!