0
while True:
    p = []
    q = []
    H = []
    E = []
    for m in range(n):
        p = (i-d[m-2][1])/d[m-2][0]
        q.append(p)
    print q

    r = q[0]
    if r  < g[1][0]:
        r == g[1][0]
    elif r > g[1][1]:
        r == g[1][1]
    print r

对于上面编码的问题,我想用更简单的方式解释一下。

i = [3,5]

r = [5,6]

if i[0] < r[0]:
    i[0] == r[0]
    print i

但是,我无法进入[5,5]这个例子,为什么?输出仍然[3,5]

4

3 回答 3

1

Change

i[0] == r[0]
r == g[1][0]
r == g[1][1]

to (respectively)

i[0] = r[0]
r = g[1][0]
r = g[1][1]

== is a logical comparison (it tests whether the two values are equal and returns False or True). = is the assignment operator.

于 2013-03-24T15:27:03.170 回答
1

以下几行是比较而不是赋值:

    r == g[1][0]
    r == g[1][1]
    i[0] == r[0]

我怀疑你打算写

    r = g[1][0]
    r = g[1][1]
    i[0] = r[0]
于 2013-03-24T15:25:52.733 回答
0
i[0] == r[0] --> i[0] = r[0]
r == g[1][0] --> r = g[1][0]
r == g[1][1] --> r = g[1][1]
于 2013-03-24T17:11:06.233 回答