在python中while循环中打印错误

时间:2017-03-20 22:40:17

标签: python python-3.x while-loop

Helli我是初学程序员,我遇到了打印语法错误,我不知道为什么......

def Input_Q_bounds (lower,upper):
    delta_x = .1

    #since there are 100 iterations
    J=np.zeros(101)
    for i in range(101) :
        Q=(i*delta_x)+(delta_x/2)
        if lower <=(Q_i)<= upper :
            Q_i =1
        else :
            Q_i=0
        #now fill the matrix
        J[i]=(Q+(9.5*(J[i-1])))/10.5

        while (i==1):
            J_analytical = Q*(np.exp(upper-10)+(np.exp(lower-10))
            print(J_analytical)
                break

这是错误:

File "<ipython-input-135-25106d5ec500>", line 19
print(J_analytical)
    ^
SyntaxError: invalid syntax

2 个答案:

答案 0 :(得分:1)

上面一行中的括号不均衡 - 你有四个开放的parens和只有三个关闭的parens。

答案 1 :(得分:0)

前一行

print(J_analytical)

括号不匹配!

J_analytical = Q*(np.exp(upper-10)+(np.exp(lower-10))
                                                     ^

# change it to:
J_analytical = Q*(np.exp(upper-10)+(np.exp(lower-10)))
                                                     ^