# 佛學院學生管理系統 # 假設有一個資料庫,存放了所有學僧的個人基本資料、學習紀錄、各科成績、環保紀錄、老師評量、學習法器紀錄、出家年資、受戒紀錄等資訊 # 資料庫的名稱為 buddhist_db,資料表的名稱為 student_table # 資料表的欄位有:student_id (學生編號)、name (姓名)、gender (性別)、age (年齡)、phone (電話)、email (電子郵件)、address (地址)、 # attendance (出席狀況)、courses (修習課程)、grades (各科成績)、environment (環保紀錄)、evaluation (老師評量)、instruments (學習法器紀錄)、 # ordination (出家年資)、precepts (受戒紀錄) # 引入資料庫模組 import sqlite3 # 連接資料庫 conn = sqlite3.connect("buddhist_db.db") cursor = conn.cursor() # 定義一個函數,用來顯示學生的基本資料 def show_basic_info(student_id): # 查詢資料庫,根據學生編號,取得學生的姓名、性別、年齡、電話、電子郵件、地址 cursor.execute("SELECT name, gender, age, phone, email, address FROM student_table WHERE student_id = ?", (student_id,)) # 取得查詢結果 result = cursor.fetchone() # 如果有查詢到資料,則顯示在螢幕上 if result: print(f"學生編號:{student_id}") print(f"姓名:{result[0]}") print(f"性別:{result[1]}") print(f"年齡:{result[2]}") print(f"電話:{result[3]}") print(f"電子郵件:{result[4]}") print(f"地址:{result[5]}") # 如果沒有查詢到資料,則顯示錯誤訊息 else: print(f"沒有找到學生編號為 {student_id} 的資料") # 定義一個函數,用來顯示學生的學習紀錄 def show_learning_record(student_id): # 查詢資料庫,根據學生編號,取得學生的出席狀況、修習課程、各科成績 cursor.execute("SELECT attendance, courses, grades FROM student_table WHERE student_id = ?", (student_id,)) # 取得查詢結果 result = cursor.fetchone() # 如果有查詢到資料,則顯示在螢幕上 if result: print(f"學生編號:{student_id}") print(f"出席狀況:{result[0]}") print(f"修習課程:{result[1]}") print(f"各科成績:{result[2]}") # 如果沒有查詢到資料,則顯示錯誤訊息 else: print(f"沒有找到學生編號為 {student_id} 的資料") # 定義一個函數,用來顯示學生的環保紀錄 def show_environment_record(student_id): # 查詢資料庫,根據學生編號,取得學生的環保紀錄 cursor.execute("SELECT environment FROM student_table WHERE student_id = ?", (student_id,)) # 取得查詢結果 result = cursor.fetchone() # 如果有查詢到資料,則顯示在螢幕上 if result: print(f"學生編號:{student_id}") print(f"環保紀錄:{result[0]}") # 如果沒有查詢到資料,則顯示錯誤訊息 else: print(f"沒有找到學生編號為 {student_id} 的資料") # 定義一個函數,用來顯示學生的老師評量 def show_evaluation_record(student_id): # 查詢資料庫,根據學生編號,取得學生的老師評量 cursor.execute("SELECT evaluation FROM student_table WHERE student_id = ?", (student_id,)) # 取得查詢結果 result = cursor.fetchone() # 如果有查詢到資料,則顯示在螢幕上 if result: print(f"學生編號:{student_id}") print(f"老師評量:{result[0]}") # 如果沒有查詢到資料,則顯示錯誤訊息 else: print(f"沒有找到學生編號為 {student_id} 的資料") # 定義一個函數,用來顯示學生的學習法器紀錄 def show_instruments_record(student_id): # 查詢資料庫,根據學生編號,取得學生的學習法器紀錄 cursor.execute("SELECT instruments FROM student_table WHERE student_id = ?", (student_id,)) # 取得查詢結果 result = cursor.fetchone() # 如果有查詢到資料,則顯示在螢幕上 if result: print(f"學生編號:{student_id}") print(f"學習法器紀錄:{result[0]}") # 如果沒有查詢到資料,則顯示錯誤訊息 else: print(f"沒有找到學生編號為 {student_id} 的資料") # 定義一個函數,用來顯示學生的出家年資和受戒紀錄 def show_ordination_record(student_id): # 查詢資料庫,根據學生編號,取得學生的出家年資和受戒紀錄 cursor.execute("SELECT ordination, precepts FROM student_table WHERE student_id = ?", (student_id,)) # 取得查詢結果 result = cursor.fetchone() # 如果有查詢到資料,則顯示在螢幕上 if result: print(f"學生編號:{student_id}") print(f"出家年資:{result[0]}") print(f"受戒紀錄:{result[1]}") # 如果沒有查詢到資料,則顯示錯誤訊息 else: print(f"沒有找到