每月信用卡支付计算器

2024-09-30 22:10:04 发布

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

如果一个人只支付信用卡公司要求的最低月供,这个程序应该在一年后计算信用卡余额。当我试着运行它时,它显示了一个语法错误,我不知道为什么。这是我的密码:

def ccb(balance, annualInterestRate, monthlyPaymentRate):
    monthlyInterestRate = annualInterestRate / 12.0
    month = 0
    for calc in range(12):
        minMonthlyPaymentRate = balance * monthlyPaymentRate
        unpaidBalance = balance - minMonthlyPaymentRate
        interest = monthlyInterestRate * unpaidBalance
        print ("Month | Balance | Unpaid Balance | Interest")
        print (month + " | " + round(balance) + " | " + round(unpaidBalance) + " | " + Interest)
        balance = unpaidBalance + Interest
        month += 1 
    print ("Remaining balance: " + round(balance))

Tags: 程序公司信用卡余额printbalanceroundmonth
1条回答
网友
1楼 · 发布于 2024-09-30 22:10:04

有几件事(尽管没有一件会在评论中抛出SyntaxError——附议Andrew,如果是SyntaxError——分享完整的信息):

1)不能隐式地将整数转换为字符串,需要强制转换它。例如:

str(round(balance))

而不是

round(balance)

2)“利益”从未定义,但“利益”是。你知道吗

修好了,一切都好。你知道吗

而且,this可能是相关的;)

相关问题 更多 >