` lines_maxlenth = 0
line_numbers = 1
hh_in = open("demo.py","r").readlines()
hh_out = open("demo_new.py", "w") # 运行生成一个demo new.py文件
for i in hh_in:
if(lines_maxlenth < len(i)): #寻找最长语句行长度
lines_maxlenth = len(i)
for i in hh_in:
i = i.ljust(lines_maxlenth+1).replace('\n','') + '#' + str(line_numbers) + "\n"
line_numbers += 1 # 每行行号增加
hh_out.write(i
students = {}
f= open(r'C:\Users\zym\students.csv','r')
lines = f.readlines()
print(lines)
for line in lines:
templ=line.split(',')
print(templ)
xuehao = templ[0]
xingming = templ[1]
students[xuehao] = [xingming]
#students[line.split(',')[0] = line.split(',')[1]
print(students)
f.close()
#随机抽取N个学号
import random
num = int(input("输入你要抽取的人数:"))
# 把字典中的key取出来,转化为列表
students.keys()
xuehao_list = random.sample(students.keys(),num)
xuehao_list
#根据抽取的结果,打印姓名
for xuehao in xuehao_list:
print(students[xuehao])
def move(play_list,num):
while num > 0:
play_list.append(play_list.pop(0))
num = num -1
return play_list
def play(players,step,stop):
play_list = [i for i in range(1,players+1)]
num = step -1
while len(play_list) > stop:
play_list = move(play_list,num)
play_list.pop(0)
return play_list