ps1b question... bal = float(raw_input("Enter the outstanding balance on your " "credit card: ")) annual_rt = float(raw_input("Enter the annual credit card interest " "rate as a decimal: ")) monthly_rt = annual_rt / 12 monthly_pymt = 0.0 balance = bal while balance > 0.0: monthly_pymt += 10 month = 0 balance = bal while balance > 0 and month < 12: month += 1 balance = balance * (1 + monthly_rt) - monthly_pymt print "months needed", month print "monthly payment needed"
I figured out that an embedded while loop was necessary but why do you have to initialize a new "balance" variable and why do you have to initialize it again inside the first while loop?
Because in the line balance = balance * (1 + monthly_rt) - monthly_pymt the Right Hand Side has a balance, so that needs to have a value, otherwise the expression has no value and then the a new value for balance cannot be assigned. The same goes for monthly_pymt After twelve months you try with an augmented monthly_pymt, and since it is a new try, you have to start with the initial balance
Hi tendaytripper! From what I understand the answer needs to print all 12 months with all the details within each of the months. That is why you need to initialize a new balance variable so then within each month the variable of balance updates and shows you exactly what the remaining balance is, the principle paid, interest paid, minimum monthly payment is, etc etc… for that month….and at the end it'll show you after a year how much we're getting screwed by credit card institutions….lol but you know thats a whole different thing altogether….anyways, printing your answer on IDLE i noticed its not displaying like the homework for the other examples….I believe you'll need to include a for loop with a count and range….so it'll display how I said it….i got that far….but i don't know how to get the values to update within the for loop…..let me know where you are….i would love to collaborate! Thanks!
Join our real-time social learning platform and learn together with your friends!