cad2023_ag4

  • Home
    • SMap
    • reveal
    • blog
  • About
  • Brython
  • 名單
  • 座位表程式
    • 程式碼
    • 程式示範網頁
    • 座位表成果
  • 繪圖檔案
  • 安裝繪圖套件
    • SOLIDWORKS
    • cero
  • 課程總結
    • 41123111
    • 41123112
    • 41123114
    • 41123115
    • 41123117
    • 41123126
    • 41123128
    • 41123136
座位表程式 << Previous Next >> 程式示範網頁

程式碼

# Brython code starts
from browser import document, html

# get output html location
brython_div = document["brython_div1"]
brython_div <= html.P(id="output_table")

# Replace this line with the actual file content
file_content = open("https://mde.tw/cadnote/downloads/2a_w12_seat.txt").read()

# Create a dictionary to store student numbers and seat numbers
seat_map = {}

# Process each line of the file content
for line in file_content.splitlines():
    # Split each line using tabs
    elements = line.split("\t")

    # If the line contains seat information
    if len(elements) == 2 and "(" in elements[1]:
        # Extract student number and seat information
        stud_num = elements[0].strip()
        seat_info = elements[1].strip()

        # Add student number and seat information to the dictionary
        seat_map[stud_num] = seat_info

# Find the maximum row and column values
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())

# Initialize a 2D list to represent the seating arrangement
seating_arrangement = [["缺席👎"] * max_col for _ in range(max_row)]

# Populate the seating arrangement with student information
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}"

# Display the result in the HTML document
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>"

# Update the HTML content with the result
document["output_table"].html = result_html
# Brython code ends

座位表程式 << Previous Next >> 程式示範網頁

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