W10 <<
Previous Next >> W11
Task 1
讀取 stage3_2a.txt , 建立 Stage3 的分組倉儲, 分組網頁, 以及各組員倉儲及網頁連結。
(此程式由Stage3-ag1組長 40823131 所製作)
# open file, default is read mode, since txt content no chinese char4
# no encoding = "UTF-08" is needed
with open("123.txt") as fh:
#匯入txt內容
data = fh.readlines()
data = [a.replace('4823122','40823122') for a in data]
#由於22號座號打錯少打0,給後傳回data
data = [b.replace('\t\t\t\t','') for b in data]
#第三組的組員只有6人,多讀取了四個空格,因此多了四個\t,將其刪除後匯入data
print(data)
for i in range(len(data)):
#(len(data))=6,共有六組
group = data[i].rstrip("\n").split("\t")
#刪除data中的\n,並將\t作為分隔的依據
print('<p>'+group[0]+'|<a href="https://'+group[1]+'.github.io/stage3-ag'+group[0][9]+'">網站</a>|<a href="https://github.com/'+group[2]+'/stage3-ag'+group[0][9]+'">倉儲</a></p>')
#用for迴圈增添每個小組的超連結網址
#print : 將字串顯示在螢幕上
#group[0] :文字檔中每一條第一個值、[1]:文字檔中每一條第二個值
#group[0][9]:文字檔中每一條第一個值的第九位
for z in range(2,18,2):
#range(2,18,2):選取文字檔中的第2格到第18格,每跳兩格選一次
try:
print('<p>'+group[z]+'|Website:'+'<a href="https://'+group[z]+'.github.io/cd2021'+'">'+group[z]+'</a>'+'|Repository:'+'<a href="https://github.com/'+group[z]+'/cd2021'+'">'+group[z]+'</a></p>')
#用for迴圈增添每個組員的超連結網址
#group[z] : 選取z跳的值
except:
continue
#由於有一組是6人,在執行程式時會超出範圍影響輸出,所以需用try execot解決
W10 <<
Previous Next >> W11