(全班共54人,共9個小組)
import random
def
rand
(_min_, _max_, _times_, _type_)
: t =
0 check =
# 建立空列表,用於儲存隨機生成的整數
while t != _times_:
num = random.randint(_min_, _max_)
# 使用使用者輸入的範圍隨機生成整數
# 避免重複,將已生成的數儲存進列表
ifnot
(num in check)
: t +=
1 check.sort(reverse=
false
)# 對列表按數字大小從小到大重新排序
if _type_ ==
'class'
:# 以隨機點名形式輸入
for result in check:
(str
(result)
+"號"
)elif _type_ ==
'group'
:# 以隨機點組形式輸出
for result in check:
(str
(result)
+"組"
)
def
main()
:while
true
: opr =
input
("\n請選擇功能: (輸入數字後按回車)\n1. 隨機點名\n2. 隨機點組\n3. 退出\n>>> "
)if opr ==
'1':
# 1. 隨機點名
# 使用者輸入點名學號範圍,即最小學號與最大學號
min_ =
int(
input
("\n輸入學號範圍: (1-54):\n最小學號: "))
max_ =
int(
input
("最大學號: "))
times_ =
int(
input
("輸入抽取人數(小於"
+str
(max_ - min_ +1)
+"): "))
("點名結果: "
) rand(_max_=max_, _min_=min_, _times_=times_, _type_=
'class'
)input
("按回車鍵返回主選單. "
)elif opr ==
'2':
# 2. 隨機點組
times_ =
int(
input
("\n抽取小組數量: "))
("點名結果: "
) rand(_min_=
1, _max_=
9, _times_=times_, _type_=
'group'
)input
("按回車鍵返回主選單. "
)elif opr ==
'3':
# 3. 退出
exit(
0)
import random
defrand
(_min_, _max_, _times_, _type_)
: t =
0 check =
while t != _times_:
num = random.randint(_min_, _max_)
ifnot
(num in check)
: t +=
1 check.sort(reverse=
false
)if _type_ ==
'class'
:for result in check:
(str
(result)
+"號"
)elif _type_ ==
'group'
:for result in check:
(str
(result)
+"組"
)def
main()
:while
true
: opr =
input
("\n請選擇功能: (輸入數字後按回車)\n1. 隨機點名\n2. 隨機點組\n3. 退出\n>>> "
)if opr ==
'1':
min_ =
int(
input
("\n輸入學號範圍: (1-54):\n最小學號: "))
max_ =
int(
input
("最大學號: "))
times_ =
int(
input
("輸入抽取人數(小於"
+str
(max_ - min_ +1)
+"): "))
("點名結果: "
) rand(_max_=max_, _min_=min_, _times_=times_, _type_=
'class'
)input
("按回車鍵返回主選單. "
)elif opr ==
'2':
times_ =
int(
input
("\n抽取小組數量: "))
("點名結果: "
) rand(_min_=
1, _max_=
9, _times_=times_, _type_=
'group'
)input
("按回車鍵返回主選單. "
)elif opr ==
'3':
exit(0)
if __name__ ==
'__main__'
: main(
)
Python3 tkinter 課堂隨機點名打分
設計乙個學生課堂tkinter介面,包括隨機點名,回答問題加分減分,儲存修改內容並退出等功能。示例操作如下 包含三個檔案 姓名 回答次數 課堂分數 後裔 0 50 妲己 0 50 蘭陵王 0 50 虞姬 0 50 白起 0 50 魯班 0 50 瑤 0 50 王昭君 0 50 凱爹 0 50 韓信 ...
Python學習 隨機點名系統
為了上課時間能夠隨機抽點學生,就利用python做了這個隨機點名系統 實現的功能會讀取檔案裡內第乙個格式為.xlsx的檔案,如果該檔案裡面有姓名,學號兩列資料就能夠正常執行,注意列名必須為姓名,學號。如果點名的時間想放 在資料夾內部放入 即可,需要將 名修改為 點名.目前存在問題是啟動速度慢,不知道...
python3實現隨機數
python3實現隨機數,供大家參考,具體內容如下 random是用於生成隨機數的,我們可以利用它隨機生成數字或者選擇字串。random.seed x 改變隨機數生成器的種子seed。一般不必特別去設定seed,python會自動選擇程式設計客棧seed。random.random 用於生成乙個隨機...