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

can someone tell me what i'm doing wrong? on problem set 1, the compound interest one. I finally got everything to work except the round function. I put it inside the loop but it only rounds the result for the first month. I can post my code if it helps.

OpenStudy (anonymous):

just realized I can attach files

OpenStudy (anonymous):

What version are you using - 3.0 print is a function, so that could create errors. Also, There's a space between float, take it out, That may help.

OpenStudy (anonymous):

using 2.7, ill try taking that space out

OpenStudy (anonymous):

also, make a function out of it, instead of while, and use the variables as arguments. Call it again using recursion like: def functionname(): ....code; a+= 1.0; functionname(); ...

OpenStudy (anonymous):

okay

OpenStudy (anonymous):

but it works exactly like it should until I try to round. shouldn't it loop with everything else?

OpenStudy (anonymous):

yeah. I just like functions because they look cleaner and they're easier to work with for me. It's not necessary

OpenStudy (anonymous):

sorry im just new to this just trying to figure out what im missing.

OpenStudy (anonymous):

I'm not familiar with round and float because I never had to extensively use it. Sorry You're code looks fine

OpenStudy (anonymous):

yea not really an error technically, its just not giving me the result I want. it rounds the value once even though its inside the loop

OpenStudy (anonymous):

ok np I appreciate the help

OpenStudy (anonymous):

I would do v += 0.00000000000; I'm gone now.

OpenStudy (anonymous):

ok thanks

OpenStudy (anonymous):

yeah ok

OpenStudy (anonymous):

The `round` function returns the rounded value, it doesn't change the given variable. you should do `v = round(v,2)`

OpenStudy (anonymous):

oh, ok thank you.

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!