每个班级与其他班级的比赛结果随机生成,0表示平局,-1表示输掉比赛,1表示赢得比赛,第一行数据表示1班对战16个班的比赛结果(每个班和自己的对战结果都用平局表示)
代码如下,请完成代码填空:
import random
import pandas as pd
s=[[0 for i in range(16)]
for jin range(16)] #生成16*16的二维列表(图1所示)
k=[];n=[]
m=[[1,0,0],[2,0,0],[3,0,0],[4,0,0],[5,0,0],[6,0,0],[7,0,0],[8,0,0],[9,0,0],[10,0,0],[11,0,0],[12,0,0],[13,0,0],[ 14,0,0],[15,0,0],[16,0,0]]
#m列表[1,0,0]中第一个元素表示第几班,第二个元素表示胜场数,第三个元素表示输场数以此类推
for i in range(1,16):
for j in range(i):
s[i][j]=random.randint(-1,1)
df=pd.DataFrame(s,index=["1班","2班","3班","4班","5班","6班","7班","8班","9班","10班","11 班","12班","13班","14班","15班","16班"],columns=["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16"])
print(df) #生成16个班的对战结果
for i in range(16):
for j in range(16):
if s[i][j]==1:
m[j][1]+=s[i][j]
elif s[i][j]==-1:
#对生成的m列表里的16个班级的数据进行排序,以胜场数作为主要关键词进行降序排序,以输场数为次要关键词进行升序排序,使m列表中的元素按照班级排名从高到低的顺序依次排列。
代码略
i=0
while i<15:
n.append(m[i][0])
for jin range(i+1,16):
if :
n.append(m[j][0])
else:
break
k.append(n)
n=[]; i=j
print("获得冠军的班级有:",k[0],"班,获得亚军的班级有:",k[1],"班,获得季军的班级有:",k[2]," 班")