''' Problem Set 2, Problem 1 Write a program to calculate the credit card balance after one year if a person only pays the minimum monthly payment required by the credit card company each month. ''' # These three variables are normally provided by checking script, stolen from Test Case 1. balance = 4213 annualInterestRate = 0.2 monthlyPaymentRate = 0.04 monthlyInterestRate = annualInterestRate/12.0 totalPaid = 0 for month in range(1,13): minMonthlyPayment = monthlyPaymentRate * balance monthlyUnpaidBalance = balance - minMonthlyPayment monthlyInterest = monthlyInterestRate * balance balance = monthlyUnpaidBalance + (monthlyInterestRate * monthlyUnpaidBalance) totalPaid += minMonthlyPayment print('Month: ' + str(month)) print('Minimum monthly payment: ' + str(round(minMonthlyPayment,2))) print('Remaining balance: ' + str(round(balance,2))) print('Total paid: ' + str(round(totalPaid,2))) print('Remaining balance: ' + str(round(balance,2)))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question