40823125 協同產品設計實習

  • Home
    • Site Map
    • reveal
    • blog
  • 個人簡介
  • Stage1-ag14
    • W1
    • W2
      • 零件尺寸及示意圖
      • 分組開會紀錄
    • W4
      • PDF
  • 發球機版本
    • 第1版
    • 第2版
    • 第3版
    • 第4版
    • 第5版
  • Stage2-ag12
    • W5
    • 產品目標
    • W7
      • Heroku 網站建立
    • W9
  • 籃球機版本
    • 版本一
    • 版本二
      • 2.1
      • 2.2
      • 2.3
      • 2.4
  • ssh
  • Error exclude
  • stage3-ag6
    • task 1
      • stage3-2a
    • task 2
    • W13
      • gutlab
      • gogs操作
    • W14
      • CoppeliaSim sensor
    • W15
      • fossil 教學
      • Inverse kinematics for a 2-joint robot arm using geometry
      • Inverse kinematics for a 2-joint robot arm using algebra
    • W16
      • MTB Onshape
      • 建立 CoppeliaSim 4.1.0 MTB robot 場景
      • 手臂末端加入 components-gripper-suction pad 吸盤
      • 逆向運動學函式
      • Python remote API 逆向運動學函式
    • W18
      • Sensor
  • Collaborative flowchart
stage3-ag6 << Previous Next >> stage3-2a

task 1

讀取 stage3_2a.txt, 建立 Stage3 的分組倉儲, 分組網頁, 以及各組員倉儲及網頁連結.

老師的範例:

# open file, default is read mode, since txt content no chinese char
# no encoding = "UTF-8" is needed
with open("stage3_2a.txt") as fh:
    # readlines will read into the whole line and put into list format
    # has \n at the end of each line
    data = fh.readlines()
#print(len(data))
for i in range(len(data)):
    group = data[i].rstrip("\n").split("\t")
    print(group)
# the following will use group data to generate needed html

第一版:將學號按組別排好

with open("stage3_2a.txt") as fh:
   #先將我們存起來stage3_2a.txt打開並命名為fh
    data = fh.readlines()
    #將stage3_2a.txt的資料以串列形式存為data
for i in range(len(data)):
    group = data[i].rstrip("\n").split("\t")
    #先取出data list中的第i項,消除元素中/n,再以\t取出需要的文字
    print(group[0]+'|'+group[0])
    #先將group第0列推出
    for j in range(1,18,1):
    #設一個範圍,(1到18,每次加1,1<=j<18)
        try:
            print(group[j])
        except:
           continue
        #這邊使用try.....except,因為有一組6個人,導致有空格,所以需要用continue讓迴圈繼續跑

第二版:將40823122的學號修正

with open("stage3_2a.txt") as fh:
   #先將我們存起來stage3_2a.txt打開並命名為fh
    data = fh.readlines()
    #將stage3_2a.txt的資料以串列形式存為data
for i in range(len(data)):
    newdata = data[i].replace('4823122','40823122')
    #因為40823122的學號打錯了,所以用 replace 把舊的替換成新的
    group = newdata.rstrip("\n").split("\t")
    #先取出newdata list中的第i項,消除元素中/n,再以\t取出需要的文字
    print(group[0]+'|'+group[0])
    #先將group第0列推出
    for j in range(1,18,1):
    #設一個範圍,(1到18,每次加1,1<=j<18)
        try:
            print(group[j])
        except:
           continue
        #這邊使用try.....except,因為有一組6個人,導致有空格,所以需要用continue讓迴圈繼續跑

第三版:以網頁的形式推出,但會告知

print('<p>'+group[0]+' | <a href="https://'+group[1]+'.github.io/'+group[0]+'">Website</a> | <a href="https://github.com/'+group[2]+'/'+group[0]+'">Repository</a></p>')
IndexError: list index out of range

with open("stage3_2a.txt") as fh:
   #先將我們存起來stage3_2a.txt打開並命名為fh
    data = fh.readlines()
    #將stage3_2a.txt的資料以串列形式存為data
for i in range(len(data)):
    newdata = data[i].replace('4823122','40823122')
    #因為40823122的學號打錯了,所以用 replace 把舊的替換成新的
    group = newdata.rstrip("\n").split("\t")
    #先取出newdata list中的第i項,消除元素中/n,再以\t取出需要的文字
    print('<p>'+group[0]+' | <a href="https://'+group[1]+'.github.io/'+group[0]+'">Website</a> | <a href="https://github.com/'+group[2]+'/'+group[0]+'">Repository</a></p>')
    for j in range(1,18,2):
    #設一個範圍,(1到18,每次+2,1<=j<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> </p>')
        except:
           continue
        #這邊使用try.....except,因為有一組6個人,導致有空格,所以需要用continue讓迴圈繼續跑

第四版:將a40823112和stage3_ag修正

with open("stage3_2a.txt") as fh:
   #先將我們存起來stage3_2a.txt打開並命名為fh
    data = fh.readlines()
    #將stage3_2a.txt的資料以串列形式存為data
for i in range(6):
    #將次數限定就不會告知list index out of range了
    newdata1 = data[i].replace('4823122','40823122')
    #因為40823122的學號打錯了,所以用 replace 把舊的替換成新的
    newdata2 = newdata1.replace('\t\t','')
    #因為有一組只有6人,所以用 replace 把空位刪除
    newdata3 = newdata2.replace('_','-')
    #因為在編輯txt的時候-會變成_,所以用 replace 把_修正為-
    group = newdata3.rstrip("\n").split("\t")
    #先取出newdata list中的第i項,消除元素中/n,再以\t取出需要的文字
    print('<p>'+group[0]+' | <a href="https://'+group[1]+'.github.io/'+group[0]+'">Website</a> | <a href="https://github.com/'+group[2]+'/'+group[0]+'">Repository</a></p>')
    for j in range(1,18,2):
    #設一個範圍,(1到18,每次+2,1<=j<18)
        try:
            n = group[j].replace('40823112','a40823112')
            #因為40823112的github帳號是a40823112,所以用 replace 把帳號修正
            print('<p>'+group[j]+' | Website:'+'<a href="https://'+n+'.github.io/cd2021'+'">'+group[j]+'</a>'+' | Repository:'+'<a href="https://github.com/'+n+'/cd2021'+'">'+group[j]+'</a> </p>')
        except:
           continue
        #這邊使用try.....except,因為有一組6個人,導致有空格,所以需要用continue讓迴圈繼續跑

第五版:將連結以老師常用的形式推出

with open("stage3_2a.txt") as fh:
   #先將我們存起來stage3_2a.txt打開並命名為fh
    data = fh.readlines()
    #將stage3_2a.txt的資料以串列形式存為data
for i in range(6):
    #將次數限定就不會告知list index out of range了
    newdata1 = data[i].replace('4823122','40823122')
    #因為40823122的學號打錯了,所以用 replace 把舊的替換成新的
    newdata2 = newdata1.replace('\t\t','')
    #因為有一組只有6人,所以用 replace 把空位刪除
    newdata3 = newdata2.replace('_','-')
    #因為在編輯txt的時候-會變成_,所以用 replace 把_修正為-
    group = newdata3.rstrip("\n").split("\t")
    #先取出newdata list中的第i項,消除元素中/n,再以\t取出需要的文字
    print('<p><a href="https://github.com/'+group[1]+'/'+group[0]+'">'+group[0]+' repo</a> | <a href="https://'+group[2]+'.github.io/'+group[0]+'">'+group[0]+' site</a></p>')
    for j in range(1,18,2):
    #設一個範圍,(1到18,每次+2,1<=j<18)
        try:
            n = group[j].replace('40823112','a40823112')
            #因為40823112的github帳號是a40823112,所以用 replace 把帳號修正
            print('<p>'+'<a href="https://github.com/'+n+'/cd2021">'+group[j]+' repo</a> | <a href="https://'+n+'.github.io/cd2021">'+group[j]+' site</a></p>')
        except:
           continue
        #這邊使用try.....except,因為有一組6個人,導致有空格,所以需要用continue讓迴圈繼續跑

Anti-piracy system:

with open("stage3_2a.txt") as fh:
   #先將我們存起來stage3_2a.txt打開並命名為fh
    data = fh.readlines()
    #將stage3_2a.txt的資料以串列形式存為data
for i in range(6):
    #將次數限定就不會告知list index out of range了
    newdata1 = data[i].replace('4823122','40823122')
    #因為40823122的學號打錯了,所以用 replace 把舊的替換成新的
    newdata2 = newdata1.replace('\t\t','')
    #因為有一組只有6人,所以用 replace 把空位刪除
    group = newdata3.rstrip("\n").split("\t")
    #先取出newdata list中的第i項,消除元素中/n,再以\t取出需要的文字
    print('<p><a href="https://github.com/'+group[1]+'/'+group[0]+'">'+group[0]+' repo</a> | <a href="https://'+group[2]+'.github.io/'+group[0]+'">'+group[0]+' site</a></p>')
    for j in range(1,18,2):
    #設一個範圍,(1到18,每次+2,1<=j<18)
        try:
            n = group[j].replace('40823112','a40823112')
            n = group[j].replace('4082312','40823125')
            print('<p>'+'<a href="https://github.com/'+n+'/cd2021">'+group[j]+' repo</a> | <a href="https://'+n+'.github.io/cd2021">'+group[j]+' site</a></p>')
        except:
           continue
        #這邊使用try.....except,因為有一組6個人,導致有空格,所以需要用continue讓迴圈繼續跑


參考資料:

python 語法 renge

python 基本語法

python loop 原理

40823136 Website


stage3-ag6 << Previous Next >> stage3-2a

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