我想知道我的代码有什么问题。我已经划分了上限和下限。我每次都失去一分钱。
我分裂了上限。
def get_credit_exact_pay(balance, annualInterestRate):
monthly_interest_rate = round(annualInterestRate/12, 2)
upper_x = balance
lower_x = balance
lower_payment = round(balance/12,2)
upper_payment = round((balance * (1 + monthly_interest_rate) ** 12) / 12, 2)
我认为我在计算付款或付款增量时还缺少关于数学的一件事。
count = 0
while True:
upper_x -= upper_payment
interest = (annualInterestRate/12.0) * upper_x
upper_x += interest
lower_x -= lower_payment
interest = (annualInterestRate/12.0) * lower_x
lower_x += interest
if count == 11:
if lower_x < lower_payment and lower_x > 0:
print('l')
print ("%.2f" % lower_payment)
break
if upper_x < upper_payment and upper_x > 0:
print ("%.2f" % upper_payment)
break
count = 0
upper_x = balance
lower_x = balance
upper_payment -= .01
lower_payment += .01
continue
else:
if lower_x < 0:
lower_x = balance/2
if upper_x < 0:
upper_x = balance/2
count += 1
continue