-1

我是一名 PYTHON 初学者,正在编写一些代码,但它不起作用……你能帮我找出我的错误并纠正它吗?

到目前为止,这是我的代码:

balance=int(raw_input("Enter the outstanding balance on your credit card: "))
annualInterestRate=float(raw_input("Enter the annual credit card interest rate as a decimal: "))
monthlyPaymentRate=float(raw_input("Enter the monthly payment rate as a decimal"))

monthInterestRate = annualInterestRate / 12
monthlyPayment = monthlyPaymentRate*balance
newBalance= (balance-monthlyPayment) * (1 + monthInterestRate) #newBalance is updated balance
month=0

while month<12:
    month += 1
    monthlyPayment = (monthlyPaymentRate*balance)
    newBalance=(balance-monthlyPayment)*(1 + monthInterestRate)
    newBalance = balance
    print("Month: " + str(month))
    print("Minimum monthly payment: " + str(monthlyPayment))
    print("Remaining balance: " + str(newBalance))
4

2 回答 2

1

猜测一下,问题是newBalance = balance,它丢弃了您在前一行进行的计算并用原始余额替换它。但是,当您没有说出您所看到的“错误”时,很难确定。

于 2012-10-16T03:19:35.487 回答
0
balance = int(raw_input("Enter the outstanding balance on your credit card: "))
annualInterestRate = float(raw_input("Enter the annual credit card interest rate as a decimal: "))
monthlyPaymentRate = float(raw_input("Enter the monthly payment rate as a decimal: "))
month = 0

while month<12:
    monthlyPayment = (monthlyPaymentRate)*(balance)
    unpaidBalance = (balance)-(monthlyPayment)
    interest = ((annualInterestRate)/(12.0)) *(unpaidBalance)
    updatedBalance = (unpaidBalance)+(interest)
    month +=1
    balance = updatedBalance
    print ('Month: '+ str(month))
    print ('Minimum monthly payment:' + str(round(monthlyPayment,2)))
    print ('Remaining Balance after one year: ' + str(round(updatedBalance,2)))
于 2015-01-21T17:59:57.980 回答