file = open(r'C:\Users\Administrator\Desktop\工作簿1.csv', 'r')
lines = file.readlines()
students = {}
for line in lines:
tmp_list = line.split(',')
xuehao = tmp_list[0]
xingming = tmp_list[1]
students[xuehao] = xingming
print(students)
{'1': '张三\n', '2': '李四\n', '3': '王五\n'}
import random
num = int(input("输入你要抽取的人数:"))
xuehao_list = random.sample(students.keys(),num)
xuehao_list
输入你要抽取的人数:2
['2', '1']
for xuehao in xuehao_list:
print(students[xuehao])
李四
张三
file = open(r'C:\Users\Administrator\Desktop\工作簿1.csv', 'r')
lines = file.readlines()
students = {}
for line in lines:
tmp_list = line.split(',')
xuehao = tmp_list[0]
xingming = tmp_list[1]
students[xuehao] = xingming
print(students)
import random
num = int(input("输入你要抽取的人数:"))
xuehao_list = random.sample(students.keys(),num)
xuehao_list
for xuehao in xuehao_list:
print(students[xuehao])
{'1': '张三\n', '2': '李四\n', '3': '王五\n'}
输入你要抽取的人数:3
张三
王五
李四