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

Hey everyone! I was hoping for some help with Assignment #1 Problem #2. I have an approach that seems to work, but I am not sure the method is efficient and seems a bit cheap (I have no programming experience). Will be posting my program in the reply section. Thanks for your help!

OpenStudy (anonymous):

balance = float(raw_input('Enter the Outstanding balance on the cerdit card: ')) AIR = float(raw_input('Enter the Anunual credit card interest rate as a decimal ')) mon_int_rate = AIR/12 #monthly interest rate balance_orig = balance #storing the original balance for if later on payment = 10 #initial $10 paymment Month = 0 while balance > 0: Month = Month + 1 balance = balance*(1 + mon_int_rate)-payment #So this while loop will first evaluate $10 attempt for 1 month, then the 2nd month, then then the 3rd month and through the 12th month. Once the 13th month comes, the "if" loop below will come into play. If the $10 payment does not stop the while loop within 12 months, then everything resets, except for the payment which is raised by $10. Also in order to get back to the original balance, it was stored as balance_orig (end of long comment (CODE CONTINUES BELOW) if Month > 12: Month = 0 payment = payment + 10 balance = balance_orig print 'RESULT' print 'Monthly payment to pay off debt in 1 year: $' + str(payment) print 'Number of months needed: ' + str(Month) print 'Balance: $' + str(round(balance, 2))

OpenStudy (anonymous):

Just ran your code, it runs fine and checks with the examples. You say you're just a beginner so I'm not sure if 100% clean and efficient code is what you should be looking for. Instead, practicing problem solving and gaining insight into how the manipulate the computer should be a priority. That being said, there are other operators and tricks you learn as you keep coding that may end up making this script even better.

OpenStudy (anonymous):

How did you do the first question? I'm so confused

OpenStudy (anonymous):

Are you confused about my program for the second problem that you need to see how I did the first? Or are you confused about the how to do the first problem? Sorry if that came off rude, just wanted clarification. I have provided my program for the 1st problem below, if you have questions or concerns please ask. balance = float(raw_input('Enter Outstanding Balance on Your Credit Card ')) AIR = float(raw_input('Enter the annual credit card interest rate as a decimal: ')) MMPR = float(raw_input('Enter the minmum monthly payment rate as a decimal: ')) Total_Paid = 0 for Month in range(1, 13): Min_Month_Paymnt = round(MMPR*balance, 2) Interest_Paid = round((AIR/12.0)*balance, 2) Principle_Paid = round(Min_Month_Paymnt - Interest_Paid,2) balance = balance - Principle_Paid Total_Paid = Total_Paid + Min_Month_Paymnt print 'Month:' + str(Month) print 'Minimum Monthly Payment: $' + str(Min_Month_Paymnt) print 'Principle Paid: $' + str(Principle_Paid) print 'Remaining balance: $' + str(balance) print '' print '' print 'RESULT' print 'Total paid: $' + str(Total_Paid) print 'Remaining balance: $' + str(balance)

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!