Python代码来查找信用卡支付

2024-05-16 00:37:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个初级的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))

Tags: the代码inputrawcardprintenterbalance
2条回答
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)))

猜猜看,问题是newBalance = balance,它将放弃您在前一行继续进行的计算,并将其替换为原始余额。但是当你没有说出你看到的是什么“错误”时,很难确定。在

相关问题 更多 >