0

我有一个错误:

“回溯(最近一次调用最后一次):文件“C:\Python27\Lib\idlelib\Task4”,第 13 行,在 if (y[i]-3)

使用以下代码:

from numpy import*
from matplotlib import pyplot
import random 
Player1 = raw_input("Player 1 Name:")
Player2 = raw_input("Player 2 Name:")
pyplot.axis([0,8000,0,200])
a = random.randint(0,101)
x = range(8000)
y = [a]`enter code here`
i=0
while i<len(x):
    b = random.randint(0,101)
    if (y[i]-3)<b and b<(y[i]+3):
        y.append(b)
    i+=1

pyplot.plot(x,y)
pyplot.show()

请帮忙!谢谢!

4

1 回答 1

0

我想您打算执行以下操作。

if(y[0]-3)<b and b<(y[0]+3) ...

或者

if(a-3)<b and b<(a+3) ...

y=[a]语句生成一个元素list,该元素仅包含生成的randint.

在 Python 中有一个更好的技巧。Python,厉害了,下面的也能看懂

if (a-3) < b < (a+3) ...
于 2013-11-02T21:12:24.460 回答