This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from browser import document, html | |
| num = 11 | |
| # 利用 document[] 取得 id 為 "brython_div1" 的位置, 然後與 brython_div1 變數對應 | |
| brython_div1 = document["brython_div1"] | |
| for i in range(num): | |
| # 利用 Brython 的 "<=" 特殊符號, 將右值帶有字串與超文件內容物件插入 brython_div1 變數所指定的位置 | |
| # 其中利用 html.A 建立 anchor 標註物件, 第一個變數為 anchor 字串, 第二個變數則為 hyper text reference | |
| brython_div1 <= str(i+1) + ". " + html.A("ag" + str(i+1), href="https://mdecd2025.github.io/2a-" + "ag" + str(i+1)) | |
| brython_div1 <= " | " + html.A("repo", href="https://github.com/mdecd2025/2a-" + "ag" + str(i+1)) | |
| # 利用 html.BR() 插入 break 標註 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # 從 Brython 程式庫中的 browser 導入 html, 可用來輸出超文件內容 | |
| # 而所導入的 document 可以指向網頁中的特定 id 內容 | |
| from browser import html, document | |
| # 建立 url 變數與網站中 2a 學員的學號與帳號資料 URL 網誌字串對應 | |
| url = "https://mde.tw/list/2a.txt" | |
| # 利用 open() 物件中的 readlines() 方法, 取出網站中的資料並逐行放入數列中, 因此 data 的資料型別為數列 | |
| data = open(url).readlines() | |
| # 進行資料查驗時, 印出 data 數列內容 | |
| #print(data) | |
| # 因為學員資料中的第一列為標題, 因此有效資料從索引值 1 開始 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from browser import html | |
| from browser import document as doc | |
| # 利用 html 建立 canvas 超文件物件 | |
| canvas = html.CANVAS(width=300, height=300) # 設定迷宮畫布大小 | |
| brython_div = doc["brython_div1"] | |
| brython_div <= canvas | |
| # 取得 canvas 的繪圖上下文 | |
| ctx = canvas.getContext("2d") | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from browser import html | |
| from browser import document as doc | |
| # 利用 html 建立 canvas 超文件物件 | |
| canvas = html.CANVAS(width=800, height=800) # 設定迷宮畫布大小 | |
| brython_div = doc["brython_div1"] | |
| brython_div <= canvas | |
| # 取得 canvas 的繪圖上下文 | |
| ctx = canvas.getContext("2d") | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from browser import html | |
| from browser import document as doc | |
| # 利用 html 建立 canvas 超文件物件 | |
| canvas = html.CANVAS(width=300, height=300) # 設定迷宮畫布大小 | |
| brython_div = doc["brython_div1"] | |
| brython_div <= canvas | |
| # 取得 canvas 的繪圖上下文 | |
| ctx = canvas.getContext("2d") | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from browser import html | |
| from browser import document as doc | |
| # 利用 html 建立 canvas 超文件物件 | |
| canvas = html.CANVAS(width=500, height=500) | |
| brython_div = doc["brython_div1"] | |
| brython_div <= canvas | |
| # 取得 canvas 的繪圖上下文 | |
| ctx = canvas.getContext("2d") | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def addto_avoid_8(init, upto): | |
| # 初始化總和為 0 | |
| sum_avoid_8 = 0 | |
| # 遍歷從 init 到 upto 之間的數字 | |
| for i in range(init, upto + 1): | |
| if '8' not in str(i): # 檢查數字是否包含 '8' | |
| sum_avoid_8 += i # 累加不包含 '8' 的數字 | |
| print(f"從 {init} 累加到 {upto} 避開包含 '8' 的數字後的總和為: {sum_avoid_8}") | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def addto_only_even(init, upto): | |
| # 初始化總和為 0 | |
| sum_even = 0 | |
| # 遍歷從 init 到 upto 之間的數字,並只累加偶數 | |
| for i in range(init, upto + 1): | |
| if i % 2 == 0: # 檢查是否為偶數 | |
| sum_even += i # 累加偶數 | |
| print(f"從 {init} 累加到 {upto} 的偶數總和為: {sum_even}") | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # sum 初始值設為 0 | |
| sum = 0 | |
| def addto(init, upto): | |
| global sum | |
| #init = 1 | |
| #upto = 100 | |
| # 利用 for 重複迴圈與變數加法進行累加 | |
| for i in range(init, upto+1): | |
| sum = sum + i | |
| print("從" + str(init) + "累加到" + str(upto) + "=" + str(sum)) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # sum 初始值設為 0 | |
| sum = 0 | |
| init = 1 | |
| upto = 100 | |
| # 利用 for 重複迴圈與變數加法進行累加 | |
| for i in range(init, upto+1): | |
| sum = sum + i | |
| print("從" + str(init) + "累加到" + str(upto) + "=" + str(sum)) | 
NewerOlder