2017-10-14 50 views
-5

这里计算每月付款指令到锻炼和我得到使用二分法

错误陈述

[enter image description here] [1

这里是我的一段代码:

def count(balance, annualInterestRate): 
    newbalance = balance 
    epsilon = 0.01 
    mir = annualInterestRate/ 12.0 
    lower = balance/12 
    upper = (balance*(1 + (mir)**12)/12.0) 
    ans = (lower + upper)/ 2.0 
    while ans*12 - newbalance >= epsilon: 
     for x in range(0, 12): 
      balance = (newbalance - ans) * (1 + mir) 
     if balance > 0: 
      Lowerpayment = ans 
     elif balance < 0: 
      Upperpayment = ans 


    print("Lowest Payment: " + str(round(ans, 2))) 

enter image description here

+3

请阅读[帮助]的材料,把一个[MCVE],**文字**,成这个问题。 – jonrsharpe

+0

您似乎有几个逻辑错误。例如,'for range in(0,12):'对'x'没有任何作用。您已重新计算完全相同的“余额”12次 –

回答

-2

我认为你只是有一个语法错误。

在Python 3,你需要把你的周围打印语句支架,像这样

print("hello") 
+0

谢谢,但它没有奏效。 –