信用卡还款计算器

2024-05-08 17:19:50 发布

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

早上好,我已经很久没有玩python了,我似乎忘记了一点

我正在尝试制作一个还款信用卡还款计算器,我已经让它工作了,但我正在努力改进它。目前它的工作,如果我填写一个付款金额,这将告诉我需要多长时间才能支付,但我想填写的付款数量,然后告诉我需要支付多少。这是我的密码,有人能告诉我正确的方向吗

original_amount = amount = 500
repayment = 1
interest = 30.34

total_interest = 0
number_of_payments = 8


def calculate_interest(old_balance):
    global interest
    global monthly_interest
    global total_interest
    monthly_interest_percent = interest / 100 / 12
    monthly_interest = old_balance * monthly_interest_percent
    new_balance = old_balance + monthly_interest
    total_interest += monthly_interest
    return new_balance


count = 0


while amount > 0:
    card_value = calculate_interest(amount)
    amount = card_value - repayment
    count += 1

    if count > number_of_payments:
        repayment += 1