cd2021 - 40823109

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • Stage1
    • W1
      • SSH setup
      • set website
    • W2
      • 草圖繪製
      • 3D圖繪製
    • W3
      • 3D爆炸圖與工作圖
      • 傳動設計修改
    • W4
  • stage2
    • W5
    • W6
    • W7
    • W8
    • W9
  • stage3
    • W10
      • task1
      • task2
    • W11
      • task 3
    • W13
    • W15
      • using geometry
      • using algebra
    • W16
      • 1. Onshape 零組件繪製
      • 2.建立 CoppeliaSim 4.1.0 MTB robot 場景
      • 3.手臂末端加入吸盤
      • 4.逆向運動學函式
      • 5.Python remote API 逆向運動學函式
    • 專案成果
  • w18
    • 期末報告影片
  • Questions and answers
    • ValueError
    • pip無法使用
    • leo 無法使用
W10 << Previous Next >> task2

task1

利用python程式讀取 stage3_2a.txt,建立 Stage3 的分組倉儲,分組網頁,以及各組員倉儲及網頁連結。

程式與註解如下 :

# 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檔內容.將它命名為fh
    data = fh.readlines()
     #readlines()方法讀取整個檔案所有行,儲存在一個列表(list)變數中,每行作為一個元素。
    data = [a.replace('4823122','40823122') for a in data]
     #因為有一個學號少打了一個0,所以使用replace() ,將正確學號取代錯誤學號,並傳回data。
    data = [c.replace('\t\t\t\t','') for c in data]
     #有一組只有6人,因此需消除後面多的2格空格。
    data = [b.replace('_','-') for b in data]
     #將_更改成-以方便之後的讀取。
     #print(data)
     #印出data。
#print(len(data))
for i in range(len(data)):
    # 使用range設定範圍,len(data)=6進行for迴圈,變數為i。
    group = data[i].rstrip("\n").split("\t")
    #將data列表中第i項,去除元素\n(換行)利用\t(空格)分割變成元素(逗號自動補上)
    
    #group()用來提出分組截獲的字符串,()用來分組。
    #rstrip() 删除 string 字符串末尾的指定字符。
    #split() 通過指定分隔符對字符串進行切片,如果参数 num 有指定值,則分隔 num+1 個子字符串。
    
    #print(group)
    print('<p>'+group[0]+' | <a href="https://'+group[1]+'.github.io/stage3-ag'+group[0]+'">網站</a> | <a href="https://github.com/'+group[2]+'/'+group[0]+'">倉儲</a></p>')
    #group[0][9]=第0個第9位
    #用print依序索引group list中的元素,放入html格式,依序print出來
 
    for j in range(2,18,2):
        #range(2,18,2):選取文字檔中的第2格到第18格,每跳兩格選一次
        try:
            print('<p>'+group[j]+' | Website:'+'<a href="https://'+group[j]+'.github.io/cd2021'+'">'+group[j]+'</a>'+' | Repository:'+'<a href="https://github.com/'+group[j]+'/cd2021'+'">'+group[j]+'</a>'+' | Group Website:'+'<a href="https://'+group[j]+'.github.io/'+group[0]+'">'+group[j]+'</a></p>')
            #用print依序索引group list中的元素,放入html格式,依序print出來
                   #差別在於這行是取組員的但因為有一組只有6人超出範圍所以一定會error
        except:
            continue


W10 << Previous Next >> task2

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