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

how do you accumulate total amount paid in this program

OpenStudy (anonymous):

##OB = Outstanding Balance ##AIR = Annual Interest Rate ##MMPP = Minimum Monthly Payments Percentage ##MMP = Minimum Mnthly Payments ##IP = Interest Paid ##PP = Principal Paid ##RB = Remaining Balance OB=int(raw_input("Enter Outstanding Balance:")) AIR=float(raw_input("Enter Interest Rate(decimal):")) MMPP=float(raw_input("Enter Minimum Monthly Payment Percent(decimal):")) ##for loop each month of the year for month in range(1, 13): print "Month:",month ##calculate minimum monthly payment ##print the min monthly payment MMP = MMPP*OB print "Minimum Monthly Payment:",round(MMP, 2) ##calculate interest paid ##Print Interest Paid IP =(AIR/12.0)*OB print "Interest Paid:",round(IP, 2) ##Calculate Principal Paid, ##print Principal Paid PP = MMP-IP print "Principal Paid:",round(PP, 2) ##Remaining Balanace ##print Remaining Balance RB = OB-PP print "Remaining Balance:",round(RB, 2) ##Total Amount Paid ##print Total Ammount Paid and Remaing Balance OB=OB-PP print "RESULT:" print "Remaining Balance:",round(RB, 2)

OpenStudy (anonymous):

the total amount paid is the IP + PP but, I dont know how to make it accumulate every month

OpenStudy (turingtest):

start with some variable for the total and initialize it to 0. every time you make a payment, you add to total with a line like ``` total = total + (monthlyPayment) ```

OpenStudy (anonymous):

Im not looking for the total im looking for the amount that I paid towards the total. I tried making total amount paid = to Interest paid + principal paid but it only made it how much it paid for the month.

OpenStudy (turingtest):

could you link the pdf of the problem again please? they give the equations, you just have to put them in the right place

OpenStudy (anonymous):

yeah at the end it wants how much spent in total.

OpenStudy (turingtest):

so what part do you need exactly? the amount paid each month is the minimum monthly payment. which value are you having trouble finding?

OpenStudy (anonymous):

I need a value for the accrument of all 12 minimum monthly payments.

OpenStudy (turingtest):

that would be the total amount paid.... or do you want the total remaining balance?

OpenStudy (turingtest):

on the pdf: RESULT Total amount paid: $1131.12 <-- is this what you want? Remaining balance: $4611.46

OpenStudy (anonymous):

yes I need the total amount paid

OpenStudy (turingtest):

so what i wrote above will work at the top of your code, *before* the for loop, initiate a variable for the total payment to 0 ``` total = 0 ## your other initializations for month in range(1, 13): total = total + minMonthlyPayment ## rest of your calculations for each month print total ``` on every iteration, the value minMonthlyPayment will be added to total, and so printing it out at the end will give the total amount paid

OpenStudy (anonymous):

ohhh ok I miss read it, so instead of putting total I would be putting TAP?

OpenStudy (turingtest):

the name of the variable doesn't matter; you can call it whatever you like (there are some exceptions: i.e. can't start a variable with a number etc). By convention, variables written all in caps are reserved for global variables, which total shouldn't be (it could but that is bad design). You could call the variable that holds the total amount paid 'foo', but that doesn't mean anything. Learning good naming conventions is an important part of programming.

OpenStudy (turingtest):

so whether you call it total or totalAmountPaid or TAP or FOOOOOOOOO, it's just a box that holds a number. make sure you know what it means, and print it at the end

OpenStudy (anonymous):

so the varaible names that I assigned really should be lowercase?

OpenStudy (anonymous):

this whole program set up is pretty bad huh? I should have listed all my initializations should have been together and then my print statements afterwards

OpenStudy (turingtest):

ideally, yes. your program will run fine as is, but it is simply a convention between programmers to use certain patterns caps for global variables example: TOTAL_PAID "camel casing" or underscores for functions and normal 'scoped' variables example: totalPaid, total_paid capitalized first letter for classes (you haven't studied those yet) example: class TotalPaid

OpenStudy (anonymous):

I was at one point doing a online class on java and we went over classes. so im guessing thats when you make a varaible in one class you would us class <class name> to call a variable from a certain class

OpenStudy (anonymous):

use*

OpenStudy (turingtest):

yeah, but that is normal for a first go you want something like ``` ## initialize variables, including total outstandingBalance = raw_input("Outstanding Balance: ") annualInterestRate = raw_input("annual Interest Rate: ") minMonthlyPaymentRate = raw_input("Minimum Monthly Payment Rate (as decimal): ") totalPaid = 0 ## for each month of theyear for month in range (1, 13): ## do calculations minMonthlyPayment = minMonthlyPaymentRate * outstandingBalance interestPaid = annualInterestRate/12 * outstandingBalance principlePaid = minMonthlyPayment - interestPaid outstandingBalance = outstandingBalance - principlePaid totalPaid = totalPaid + minMonthlyPayment ## print out values print "Month: ", month print "Minimum Monthly Payment: ", minMonthlyPayment print "Principal Paid: ", principlePaid print "Remaining Balance: ", outstandingBalance print "RESULT" print "Total Paid: ", totalPaid print "Remaining Balance: ", outstandingBalance ```

OpenStudy (turingtest):

there i think i just wrote the answer for you, though i didn't really intend to. I didn't try running that, so if it doesn't work it's your job to debug. Hopefully you see the structure 1) initializations 2) loop with calculations 3) final results printed

OpenStudy (anonymous):

thats perfect even though my program works the same way the structure to yours is so much better!

OpenStudy (turingtest):

right, often two program that produce the same results differ drastically in their structure and approach. writing clear, legible, well-organized code is important, because when you write ir professionally, you want someone 5 years later to be able to pick up your code and follow it without too much difficulty. It also makes debugging a lot easier when your code is well organized

OpenStudy (anonymous):

thanks again your the man

OpenStudy (turingtest):

np

OpenStudy (anonymous):

just to mention something to all that are trying to solve credit card problem, U might find useful the loop material that is on the MIT portaland go through it cuz once u understand loops perfectly then by applying simple maths that becomes a solution for this particular problem.

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!