我的任务是:
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.
The following variables contain values as described below:
balance - the outstanding balance on the credit card
annualInterestRate - annual interest rate as a decimal
monthlyPaymentRate - minimum monthly payment rate as a decimal
For each month, calculate statements on the monthly payment and remaining balance, and print to screen something of the format:
Month: 1
Minimum monthly payment: 96.0
Remaining balance: 4784.0Finally, print out the total amount paid that year and the remaining balance at the end of the year in the format:
It should not specify the values for the variables balance, annualInterestRate, or monthlyPaymentRate - our test code will define those values before testing your submission.
下面是我写的代码:
def minpayment(balance, annualInterestRate, monthlyPaymentRate):
totalPaid = 0
month = 1
while month <= 12:
minPayment = monthlyPaymentRate * balance
balance -= minPayment
balance += (annualInterestRate/12.0)*balance
print 'Month:',month
print 'Minimum monthly payment:',round(minPayment,2)
print 'Remaining balance:',round(balance,2)
totalPaid += minPayment
month += 1
print 'Total paid:', round(totalPaid,2)
print 'Remaining balance:', round(balance,2)
现在,我的问题是,既然我已经创建了函数,我该如何调用它?在
你可以这样称呼它:
或者一般来说:
^{pr2}$相关问题 更多 >
编程相关推荐