第二週

列出各組組員的學號及組別

with open("2b-raw.txt") as fh:
    # 逐行讀出檔案資料, 並放入數列中
    lines = fh.readlines()
    # 設法用迴圈逐數列內容取出字串
    # 組序變數 g 起始值設為 0
    g = 0
    for i in range(len(lines)):
        # 利用 strip() 去除各行字串最末端的跳行符號
        #print(lines[i].strip())
        line = lines[i].strip()
        # 利用 split() 將以 \t 區隔的字串資料分離後納入 groups 字串
        groups = line.split("\t")
        #print(groups)
        for i in range(len(groups)):
            # 每組有三名組員
            if i%3 == 0:
                # 每三位組員組序增量 1
                g += 1
                print()
                print("第" + str(g) + "組:")
                print(groups[i])
            else:
               print(groups[i])
第1組:
40523207
40523209

第2組:
40523203
40523201
40523240

第3組:
40523216
40523232
40523213

第4組:
40523204
40523219

第5組:
40523211
40523215
40523245

第6組:
40523226
40523227
40523231

第7組:
40523222
40523210
40523224

第8組:
40523220
40523214
40523218

第9組:
40523233
40523236
40523243

第10組:
40523205
40523206
40523230

第11組:
40523238
40523244
40523239

第12組:
40523212
40523241
40523242

第13組:
40523246
40523234
40523237

第14組:
40523248
40523249
40523250

results matching ""

    No results matching ""