Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 编写一个程序,计算12个月内还清信用卡余额所需的最低每月固定付款额_Python_Python 2.7 - Fatal编程技术网

Python 编写一个程序,计算12个月内还清信用卡余额所需的最低每月固定付款额

Python 编写一个程序,计算12个月内还清信用卡余额所需的最低每月固定付款额,python,python-2.7,Python,Python 2.7,这个问题是针对Python2.7的。问题要求编写一个程序,计算在12个月内还清信用卡余额所需的最低每月固定付款额。所谓每月固定付款,我们指的是一个数字,它不会每月改变,而是每月支付的固定金额 在这个问题上,我们将不处理最低每月付款率 以下变量包含如下所述的值: 余额-信用卡上的未付余额 AnnualInterestate-以十进制表示的年利率 该计划应打印出一行:将在1年内付清所有债务的最低月付款额 假设利息根据月末的余额按月复利(在当月付款后)。每月付款必须是10美元的倍数,并且所有月份都相同

这个问题是针对Python2.7的。问题要求编写一个程序,计算在12个月内还清信用卡余额所需的最低每月固定付款额。所谓每月固定付款,我们指的是一个数字,它不会每月改变,而是每月支付的固定金额

在这个问题上,我们将不处理最低每月付款率

以下变量包含如下所述的值: 余额-信用卡上的未付余额 AnnualInterestate-以十进制表示的年利率

该计划应打印出一行:将在1年内付清所有债务的最低月付款额

假设利息根据月末的余额按月复利(在当月付款后)。每月付款必须是10美元的倍数,并且所有月份都相同。请注意,使用此支付方案,余额可能变为负值,这是可以的。所需数学总结如下:

月利率=(年利率)/12 每月更新的余额=(以前的余额-最低月付款额)x(1+月利率)

我为这个问题想出了一个密码;然而,我反复得到一个无限循环

    b = balance = 3329
    air = annualInterestRate = 0.2
    monthlyInterestRate = (air/12)
    mmp = minimumMonthlyPayment = (balance * monthlyInterestRate)
    month = 0
    while month <= 12:
        b = ((b - mmp) * (1 + (air/12)))
        month = 1 + month
        if b <= 0 and month == 12:
           break
        elif b > 0 and month == 12:
           b = balance
           month = 0
           mmp = minimumMonthlyPayment + 10.00
    print str('Lowest Payment: ' + str(round(mmp, 2)))
b=余额=3329
空气=年利率=0.2
月利率=(航空/12)
mmp=每月最低付款额=(余额*每月利息)
月份=0

而month这段代码有点奇怪,即类似以下的行:

   mmp = minimumMonthlyPayment = (balance * monthlyInterestRate)
用双等号

此代码不会被卡住:

balance = 5000
annualInterestRate = 0.2
monthlyInterestRate = (annualInterestRate/12)
minimumMonthlyPayment = (balance * monthlyInterestRate)
month = 0
while month <= 12:
    balance = ((balance - minimumMonthlyPayment) * (1 + monthlyInterestRate))
     month = 1 + month
    if balance <= 0 and month == 12:
        break
    elif balance > 0 and month == 12:
        month = 0
        minimumMonthlyPayment + 1.00

print str('Lowest Payment: ' + str(round(minimumMonthlyPayment, 2)))
余额=5000
年利率=0.2
月利率=(年利率/12)
每月最低付款额=(余额*每月利息)
月份=0

而month这段代码有点奇怪,即类似以下的行:

   mmp = minimumMonthlyPayment = (balance * monthlyInterestRate)
用双等号

此代码不会被卡住:

balance = 5000
annualInterestRate = 0.2
monthlyInterestRate = (annualInterestRate/12)
minimumMonthlyPayment = (balance * monthlyInterestRate)
month = 0
while month <= 12:
    balance = ((balance - minimumMonthlyPayment) * (1 + monthlyInterestRate))
     month = 1 + month
    if balance <= 0 and month == 12:
        break
    elif balance > 0 and month == 12:
        month = 0
        minimumMonthlyPayment + 1.00

print str('Lowest Payment: ' + str(round(minimumMonthlyPayment, 2)))
余额=5000
年利率=0.2
月利率=(年利率/12)
每月最低付款额=(余额*每月利息)
月份=0

月份首先,您必须修复月份首先,您必须修复月份
monthlyinterestate=annualinterestate/12
月付款=0
新平衡=平衡
当newbalance>0时:
月付款+=10
新平衡=平衡
月份=1
而第0个月:
新余额-=月付款
利息=月利息*新余额
新余额+=利息
月份+=1
新平衡=圆形(新平衡,2)
月利率=年利率/12
月付款=0
新平衡=平衡
当newbalance>0时:
月付款+=10
新平衡=平衡
月份=1
而第0个月:
新余额-=月付款
利息=月利息*新余额
新余额+=利息
月份+=1
新平衡=圆形(新平衡,2)

这将为您提供所有情况下的正确答案:

monthlyPayment = 10
monthlyInterestRate = annualInterestRate /12
newbalance = balance - 10

while newbalance > 0:
    monthlyPayment += 10
    newbalance = balance
    month = 0

    while month < 12 and newbalance > 0:
        newbalance -= monthlyPayment
        interest = monthlyInterestRate * newbalance
        newbalance += interest
        month += 1
    newbalance = round(newbalance,2)
print " Lowest Payment:", monthlyPayment
monthlyPayment=10
月利率=年利率/12
新天平=天平-10
当newbalance>0时:
月付款+=10
新平衡=平衡
月份=0
当月份<12且newbalance>0时:
新余额-=月付款
利息=月利息*新余额
新余额+=利息
月份+=1
新平衡=圆形(新平衡,2)
打印“最低付款额:”,按月付款

这将为您提供所有情况下的正确答案:

monthlyPayment = 10
monthlyInterestRate = annualInterestRate /12
newbalance = balance - 10

while newbalance > 0:
    monthlyPayment += 10
    newbalance = balance
    month = 0

    while month < 12 and newbalance > 0:
        newbalance -= monthlyPayment
        interest = monthlyInterestRate * newbalance
        newbalance += interest
        month += 1
    newbalance = round(newbalance,2)
print " Lowest Payment:", monthlyPayment
monthlyPayment=10
月利率=年利率/12
新天平=天平-10
当newbalance>0时:
月付款+=10
新平衡=平衡
月份=0
当月份<12且newbalance>0时:
新余额-=月付款
利息=月利息*新余额
新余额+=利息
月份+=1
新平衡=圆形(新平衡,2)
打印“最低付款额:”,按月付款
余额=3329
年利率=0.2
月利率=年利率/12
月付款=0
新平衡=平衡
当newbalance>0时:
月付款+=10
新平衡=平衡
月份=1
而第0个月:
新余额-=月付款
新天平+=(月利率*新天平)
月份+=1
打印“最低付款额:”,按月付款
我认为这将是解决你的疑问的最好办法,并且满足了你的答案。

balance=3329
monthlyPayment = 0
monthlyInterestRate = annualInterestRate /12
newbalance = balance
month = 0

while newbalance > 0:
    monthlyPayment += 10
    newbalance = balance

    for month in range(1,13):
        newbalance -= monthlyPayment
        newbalance += monthlyInterestRate * newbalance
        month += 1
print " Lowest Payment:", monthlyPayment
年利率=0.2 月利率=年利率/12 月付款=0 新平衡=平衡 当newbalance>0时: 月付款+=10 新平衡=平衡 月份=1 而第0个月: 新余额-=月付款 新天平+=(月利率*新天平) 月份+=1 打印“最低付款额:”,按月付款

我认为这将是解决你的疑问的最好办法。并且满足了答案。我认为这是一种相当简单的方法:

monthlyPayment = 0
monthlyInterestRate = annualInterestRate /12
newbalance = balance
month = 0

while newbalance > 0:
    monthlyPayment += 10
    newbalance = balance

    for month in range(1,13):
        newbalance -= monthlyPayment
        newbalance += monthlyInterestRate * newbalance
        month += 1
print " Lowest Payment:", monthlyPayment
x = 50
o = balance
a = [1,2,3,4,5,6,7,8,9,10,11,12]
monthly = annualInterestRate/12

while balance>0:
    for months in a:
        u = balance - x
        balance = u + (monthly * u)
    if balance > 0:
        x += 10
    else:
        break
print x

我认为这是一个相当简单的方法:

x = 50
o = balance
a = [1,2,3,4,5,6,7,8,9,10,11,12]
monthly = annualInterestRate/12

while balance>0:
    for months in a:
        u = balance - x
        balance = u + (monthly * u)
    if balance > 0:
        x += 10
    else:
        break
print x

这基本上是randomizertech答案的一个稍微改进版本,它允许用户输入不同的变量,而不是只输入初始余额和年利率的固定值。 最后,它会打印一些对用户有用的变量

InitialBalance = float(raw_input("Enter your current balance: "))
InterestRate = float(raw_input("Enter the yearly interest rate as a decimal: "))


monthlyPayment = 0
monthlyInterestRate = InterestRate/12
balance = InitialBalance


while balance > 0:
    monthlyPayment += 10
    balance = InitialBalance
    numMonths = 0

    while numMonths < 12 and balance > 0:

        numMonths += 1

        interest = monthlyInterestRate * balance

        balance -= monthlyPayment

        balance += interest

    balance = round(balance,2)

print "RESULT"
print "Monthly payment to pay off debt in 1 year: " , monthlyPayment
print "Number of months need to pay the debt: " , numMonths
print "Balance after debt is paid: " , balance
InitialBalance=float(原始输入(“输入当前余额”))
利率=浮动(原始输入(“以小数形式输入年利率:”)
月付款=0
月利率=利率/12
余额=初始余额
当余额>0时:
月付款+=10
余额=初始余额
numMonths=0
当numMonths<12且balance>0时:
数值+=1
利息=月利息*余额
余额-=每月付款
余额+=利息
平衡=圆形(平衡,2)
打印“结果”
打印“月份”