隨機點名 人工班)

2021-10-10 17:38:19 字數 922 閱讀 2078

# 建立乙個字典student,key是學號,value是姓名

# 學生資訊在student.csv檔案裡,從檔案中讀取並儲存到字典

# 開啟student.csv檔案

file

=open

(r'e:\學習資料夾\人工班名單csv.csv'

,'r'

)# 讀取檔案內容

lines =

file

.readlines(

)# 抽取每行的學號和姓名,儲存到字典

students =

for line in lines:

tmp_list = line.split(

',')

xuehao = tmp_list[0]

xingming = tmp_list[2]

students[xuehao]

= xingming

print

(students)

# 從學號中隨機抽取n個學號

import random

num =

int(

input

("請輸入你要抽取的人數:"))

# 如何把字典中的key(學號)抽取成列表

xuehao_list = random.sample(students.keys(

),num)

xuehao_list

請輸入你要抽取的人數:
# 根據隨機的學號,列印輸出對應的姓名

for xuehao in xuehao_list:

print

(students[xuehao]

)

隨機點名器

1.doctype html html lang en head meta charset utf 8 title 隨機點名器 title link rel icon href style box,zhu box div,button astyle head body div class box d...

js隨機點名器

今天翻到以前乙個js隨機點名效果,當時也是頭疼了幾天才做出來的,有些繁瑣,不過希望可以幫到你 github位址 瀏覽位址點名器.html 不要像我一樣html起中文名字 如下 main.js 獲取按鈕 點名和重置 var btn document.queryselector btn button 獲...

隨機點名系統

lang en charset utf 8 name viewport content width device width,initial scale 1.0 隨機點名系統title body th tab1 tab0 tab2 input style head tab0 width 1000 a...