使用python查找信用卡1年内支付的最低支付额

2024-06-21 20:37:23 发布

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

我正在努力解决这个问题。我用两种不同的方法来编写代码。我的代码没有增加足够的付款来支付全部余额。我会贴上我的两个版本。有人能提供我缺少的吗?在

Now write a program that calculates the minimum fixed monthly payment needed in order pay off a credit card balance within 12 months. By a fixed monthly payment, we mean a single number which does not change each month, but instead is a constant amount that will be paid each month.

In this problem, we will not be dealing with a minimum monthly payment rate.

The following variables contain values as described below:

balance - the outstanding balance on the credit card

annualInterestRate - annual interest rate as a decimal

The program should print out one line: the lowest monthly payment that will pay off all debt in under 1 year, for example:

Lowest Payment: 180 Assume that the interest is compounded monthly according to the balance at the end of the month (after the payment for that month is made). The monthly payment must be a multiple of $10 and is the same for all months. Notice that it is possible for the balance to become negative using this payment scheme, which is okay. A summary of the required math is found below:

Monthly interest rate = (Annual interest rate) / 12.0 Monthly unpaid balance = (Previous balance) - (Minimum fixed monthly payment) Updated balance each month = (Monthly unpaid balance) + (Monthly interest rate x Monthly unpaid balance)

功能1,我想不出能让它在12个月内得到正确的付款

def cardBalance(balance,annualInterestRate,fixedPayment,months):        
    while True:
        for month in range(months):
            balace = (balance - fixedPayment) * (1 + (annualInterestRate/12))
            if balance > 0:
                fixedPayment += 10
            else:
                break
        return('Lowest Payment: ' + str(round(fixedPayment,0)))
cardBalance(399,.2,0,12)
# returns lowest payment of 120, balance remains 293.8

函数2,我不知道如何修复

^{pr2}$

Tags: oftheforthatrateispaymentfixed