Ask your own question, for FREE!
Computer Science 13 Online
OpenStudy (anonymous):

Can somebody assist me in problem set 1? its for the first problem....(credit of $5K) ...I don't get the part to use the range and count for each month....

OpenStudy (anonymous):

Minimum_monthly_Payment = float(input('What is your outstanding balance on your credit card?')) monthly_payment = .02 * Minimum_monthly_Payment print 'Enter the annual credit card interest rate as a decimal:.2' print 'Enter the minimum monthly payment rate as a decimal: .02' range(1,13) for count in range (1,13): print 'Month:' , count interest_paid = .18/12.0 * Minimum_monthly_Payment print 'Interest paid:', interest_paid print 'Minimum monthly payment:', monthly_payment principle_paid = monthly_payment - interest_paid print 'Principle paid:', principle_paid remaining_balance = Minimum_monthly_Payment - principle_paid print 'remaining_balance:' , remaining_balance

OpenStudy (anonymous):

Fist of all, you do not need the line range(1,13). You can delete it. You have range in for loop, and you do not need it before the for loop. Now, range (1,13) is convenient way to tell Python that you need array of numbers from 1 to 12. Why 1 to 12, and not 1 to 13? It has something to do with the thing that computers count from 0, not from 1, but for now, just take it for granted. It will come to you more clear as time and lines of code go by. So, when you say range(1, 13), it will iterate from 1 to 12 and stop, 13 will be ommited. And there are 12 months, right? We have needed range, now we have to iterate through it. That's where for loop comes in. So, we'll say: for every integer in range array, update the value of variable count and execute code that follows (after colon), starting from number 1. You can call variable count any name you want, it is not reserved Python word, just the matter of your choice. And, in this case, name count is perfectly fine. For loop will work like this: in first iteration, or if you wish, in the first pass through the loop, count will have value 1, and print statement will output Month: 1. In the next step, count will be updated to 2, print will output Month: 2. All the way to 12. In the last step, count will be 12, print will output Month: 12. When count becomes 13, it will step out of range and the block of code following colon will not execute. It will jump to the first next line of code, out and after the for loop. So, here range(1,13) is acting as sort of control mechanism, which tells how many times will for loop iterate. The rest of code, put like this, generaly will not work as intended, I'm sure. But you said that you just don't get the range, count and for part, so I assume you'll deal with the rest of the code yourself. Just one more word of advice: pay attention to code indentation. Every line of code if indented will be a part of for loop, meaning that it will execute 12 times, once for each month. If not indented, it will be out of the loop and execute just once. Have fun!

OpenStudy (anonymous):

Hi Zoran! Thank you so much for your reply! It is greatly appreciated! Although, i'm still a little confused because when I run the new edited code it doesn't loop and update the values. It ends up calculating just on one month and printing the Months within the range.....

OpenStudy (anonymous):

Balance = float(input('What is your outstanding balance on your credit card?')) monthly_payment = .02 * Balance interest_paid = .18/12.0 * Balance principle_paid = monthly_payment - interest_paid remaining_balance = Balance - principle_paid for count in range (1,13): remaining_balance = Balance - principle_paid monthly_payment = .02 * remaining_balance interest_paid = .18/12.0 * remaining_balance print 'Interest paid:', interest_paid print 'Minimum monthly payment:', monthly_payment print 'Principle paid:', principle_paid print 'remaining_balance:' , remaining_balance print 'Enter the annual credit card interest rate as a decimal:.2' print 'Enter the minimum monthly payment rate as a decimal: .02' print 'Month:' , count

OpenStudy (anonymous):

Sorry Zoran i'm really new to all of this Python coding stuff. I tried to do as much as I could before replying but got really stuck at this part. I really appreciate your approach of not giving me the answer but probing me with more questions to really dig into how to think about the logic and syntax within Python. It is greatly appreciated. Cheers!

OpenStudy (anonymous):

OK, this is the solution for this problem, the way I see it. Hope this will help you to better understand what's going on in the code. Take a look at attached .py file, works like a charm. Have a nice day!

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!