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

Problem set 1(a): I coded it right but somehow my code is only showing integers in this form 16.0,no digits after the decimal. can anyone help?

OpenStudy (anonymous):

here is my code: balance=float(raw_input("ENTER BALANCE")) annual_r=float(raw_input("ENTER ANNUAL RATE")) monthly_r=float(raw_input("ENTER MINIMUM MONTHLY PAYMENT RATE")) month=1 min_mon_pay=0.0 i_paid=0.0 p_paid=0.0 remaining_balance=balance total_paid=0.0 while month<=12: min_mon_pay=float(monthly_r*balance) i_paid=float(annual_r*balance/12.0) p_paid=float(min_mon_pay-i_paid) remaining_balance=float(remaining_balance-p_paid) print "Month:",month print "MINIMUM MONTHLY PAYMENT:"+str(round(min_mon_pay,2)) print "Principle Paid:"+str(round(p_paid,2)) print "Remaining Balance:"+str(round(remaining_balance,2)) total_paid+=min_mon_pay month+=1 print "RESULT : " print "Total Amount Paid",round(total_paid,2) print "Remaining Balance",round(remaining_balance,2)

OpenStudy (anonymous):

The problem with your code is that you need to update the balance inside the loop, so you wont keep getting always the same min_mon_pay, something like balance = remaining_balance. Also inside the loop, there's no need to do float conversion since you already did it when reading the values at the beginning. Hope it helps.

OpenStudy (anonymous):

@halr2s I'm updating the bal inside the loop only. remaining_balance=float(remaining_balance-p_paid) this is inside my loop,are you talking about something else?

OpenStudy (anonymous):

Sorry I wasn't clear enough, notice how the line... min_mon_pay=float(monthly_r*balance) is using a constant balance, you need to change that so that it reflects the updated balance, otherwise you'll keep getting the same min_mon_pay every time through the loop.

OpenStudy (anonymous):

@halr2s: Thanks for the help.I did it :)

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!
Latest Questions
ShadowKid3: what are examples of a class three lever?
18 hours ago 3 Replies 2 Medals
alphaXtiger: Help pls
1 day ago 3 Replies 1 Medal
danielfootball123: What are good stocks to invest
2 days ago 3 Replies 0 Medals
Burro: 5(5x+7)+3(x+3)
2 days ago 13 Replies 2 Medals
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!