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?
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)
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.
@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?
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.
@halr2s: Thanks for the help.I did it :)
Join our real-time social learning platform and learn together with your friends!