我的代码没有在python id中运行

2024-06-25 05:27:39 发布

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

我应该写一个代码来支付信用卡债务在一年或更短的时间里,其中余额和年利率是输入和输出是一个月分期付款偿还债务在一年或更短的时间内。剩余的上限和下限所需的数学在代码中。请帮助

balance = int(raw_input())
annualInterestRate = float(raw_input())


lowestPayment = balance
monthlyPayment = 0
monthlyUnpaid = 0
temp = balance
monthlyInterest = 0

lowerBound = balance/12
upperBound = balance*((1+annualInterestRate/12.0)**12)/12.0
mid = 0

while  upperBound - lowerBound > 0.0000:
    mid = (upperBound + lowerBound)/2.0
    monthlyPayment = mid
    balance = temp
    for i in range(1,13):
        monthlyUnpaid = balance - monthlyPayment
        monthlyInterest = annualInterestRate/12.0 * monthlyUnpaid
        balance = monthlyUnpaid + monthlyInterest
    if int(balance) <= 0:
        upperBound = mid - 1
        if monthlyPayment < lowestPayment:
            lowestPayment = monthlyPayment
    elif int(balance) > 0:
        lowerBound = mid + 1


print 'Lowest Payment: '+str(round(lowestPayment,2))

Tags: 代码inputraw时间tempintbalancemid