41123114的個人倉儲

  • Home
    • SMap
    • reveal
    • blog
  • About
  • 個人評分
    • 評分依據
    • 自我評分
  • exam
    • step1
  • 網站
  • cad軟件安裝
    • Cero
    • Soliwork
  • Home Work
    • 說明如何利用chat列出各組學員座位表
      • 問題總結
      • 成品及附上說明
  • 小組
    • 零件繪製
      • 組合圖
      • 滑軌
      • 底座
      • 接球的碗
      • 支撐柱
      • 固定座
問題總結 << Previous Next >> 小組

成品及附上說明

# Brython code starts
from browser import document, html

# 獲取輸出HTML的位置
brython_div = document["brython_div1"]
brython_div <= html.P(id="output_table")

# 替換這行程式碼,使用實際的檔案內容
file_content = open("https://mde.tw/cadnote/downloads/2a_w12_seat.txt").read()

# 創建一個字典來存儲學號和座位號
seat_map = {}

# 處理檔案內容的每一行
for line in file_content.splitlines():
    # 使用tab分割每一行
    elements = line.split("\t")

    # 如果該行包含座位信息
    if len(elements) == 2 and "(" in elements[1]:
        # 提取學號和座位信息
        stud_num = elements[0].strip()
        seat_info = elements[1].strip()

        # 將學號和座位信息添加到字典中
        seat_map[stud_num] = seat_info

# 檢查 seat_map 是否為空
if not seat_map:
    # 如果未找到座位信息,顯示消息
    document["output_table"].html = "<p>找不到座位信息。</p>"
else:
    # 查找最大的行和列值
    max_row = max(int(seat_info[1]) for seat_info in seat_map.values())
    max_col = max(int(seat_info[3]) for seat_info in seat_map.values())

    # 初始化二維列表來表示座位安排
    seating_arrangement = [["空位"] * max_col for _ in range(max_row)]

    # 使用學號和座位信息填充座位安排
    for stud_num, seat_info in seat_map.items():
        row = int(seat_info[1]) - 1
        col = int(seat_info[3]) - 1
        seating_arrangement[row][col] = f"座位號: {seat_info}, 學號: {stud_num}"

    # 在HTML文檔中顯示結果
    result_html = "<table>"
    for row in seating_arrangement:
        result_html += "<tr>"
        for cell_content in row:
            result_html += f"<td>{cell_content}</td>"
        result_html += "</tr>"
    result_html += "</table>"

    # 使用結果更新HTML內容
    document["output_table"].html = result_html
# Brython code ends


問題總結 << Previous Next >> 小組

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