stage3-ag5

  • Home
    • Site Map
    • reveal
    • blog
  • Introduction
  • Stage1,2
    • stage1
      • stage2
  • week
    • w10
      • task1
      • task2
      • task3
    • w11
      • task3-1
    • w12
    • w13
    • w14
    • w15
    • w16
    • w18
  • FINAL
    • 40823124
    • 40823128
    • 40823120
    • 40823115
    • 40823140
    • 40823139
    • 40823111
task1 << Previous Next >> task3

task2

隨機抽取各組別兩學號

#by 40823124
import random
 
with open("stage3_ag1.txt") as fh: #讀取
    data=fh.readlines()
 
for i in range(len(data)):
    group=data[i].rstrip("\n").split("\t") #刪除空格
     
    subgroup=group[1:] #取組別後
    memberNum=0
    count =0
    for j in range(len(subgroup)): 
        if(subgroup[j]!=""): #取值
            count+=1
            if(count%2==0): #重複學號取1個號碼
                memberNum+=1
    print("group"+" "+str(i+1)+":"+str(memberNum)) #輸出組別人數
    beRandomGroup=[] 
    k=0
    while(k<len(subgroup)): #取學號跳過帳號
        if(subgroup[k]!=""):
            beRandomGroup.append(subgroup[k])
        k=k+2
    var=random.choice(beRandomGroup) #抽第一個
    while(1==1):
        var2=random.choice(beRandomGroup)#抽第二個
        if(var2!=var): #抽到不重複為止
            break
    print(var)
    print(var2)
    print("---------------------")

OUTPUT

group 1:8
40823123
40823136
---------------------
group 2:8
40823102
40871106
---------------------
group 3:6
40523252
40823154
---------------------
group 4:8
40823121
40823127
---------------------
group 5:8
40823115
40823128
---------------------
group 6:8
40823110
40823153
---------------------

task1 << Previous Next >> task3

Copyright © All rights reserved | This template is made with by Colorlib