由于数组大小,python中的运行时错误

时间:2013-01-02 08:06:40

标签: python arrays runtime-error

import psyco
psyco.full()
n=int(raw_input('Enter how many test cases'))
out=[]
for i in range(n):
    r=raw_input('Enter the number of people and minimum distance')  
    temppeople=''   
    tempdistance=''
    l=len(r)
    k=0
    z=0
    newpos=[]
    dis=[]
    while r[k]!=' ': k=k+1
    for j in range(k): temppeople=temppeople+r[j]
    for z in range(k+1,l): tempdistance=tempdistance+r[z]
    people=int(temppeople)
    distance=float(tempdistance)
    print 'Enter the respective distances'
    pos=[float(input()) for m in range(people)]
    if (pos[0]+pos[1])<=distance:
        newpos.append(0)
        newpos.append(distance)
        z=distance
    else:
        newpos.append(pos[0]/2)
        newpos.append((pos[0]/2)+distance)
        z=(pos[0]/2)+distance
    if people>2:
        for a in range(2,people):
            z=z+distance
            newpos.append(z)
    for b in range(people):
        dis.append((abs(pos[b]-newpos[b])))
    out.append((max(dis)))
for q in out:
    print q

我为the flushot lineup problem in code chef编写了此代码。但是它显示运行时错误。我假设这是由于数组大小。我该怎么做才能纠正代码。

0 个答案:

没有答案