#Python學生管理系統展示,增刪改查

student_list = {}
def menu():
    print("*"*30)
    print("歡迎訪問學生管理系統")
    print("1:添加學生")
    print("2:刪除學生")
    print("3:修改學生")
    print("4:顯示學生信息")
    print("5:關閉學生管理系統")
def add_student():
    id = input("請輸入學生的學號")
    name = input("請輸入學生的姓名")
    age = input("請輸入學生的年齡")
    sex = input("請輸入學生的性別")
    classname = input("請輸入學生的班級")
    student_info = {'name':name,'age':age,'sex':sex,'classname':classname}
    student_list[id] = student_info
    print("添加成功")
    
def delete_student():
    id = input("請輸入要刪除的學生學號")
    if id not in student_list.keys():
        print("您刪除的值不存在")
        delete_student()
    student_list.pop(id)
    print("您刪除了該學生信息")

def edit_student():
    id = input("請輸入要修改的學生學號")
    if id not in student_list.keys():
        print("您修改的值不存在")
        return
    student_info = student_list[id]
    print("你當前修改學生的學號%s 姓名%s 年齡%s 性別%s 班級%s"%(id,student_list[id]['name'],student_list[id]['age'],student_list[id]['sex'],student_list[id]['classname']))
    print("*"*30)
    print("請輸入要修改的內容編號")
    print("1:姓名")
    print("2:年齡")
    print("3:性別")
    print("4:班級")
    print("5:全部信息")
    print("*"*30)
    edit_choose = input("請輸入編號")
    if edit_choose == "1":
        newname = input("請輸入學生的姓名:")
        student_list[id]['name'] = newname
    elif edit_choose == "2":
        newage = input("請輸入學生的年齡")
        student_list[id]['age'] = newage
    elif edit_choose == "3":
        newsex = input("請輸入學生的性別")
        student_list[id]['sex'] = newsex
    elif edit_choose == "4":
        newclassname = input("請輸入學生的班級")
        student_list[id]['classname'] = newclassname
    elif edit_choose == "5":
        newname = input("請輸入新的學生姓名")
        newage = input("請輸入學生年齡")
        newsex = input("請輸入學生性別")
        newclassname = input("請輸入學生班級")
        student_list[id]['name'] = newname
        student_list[id]['age'] = newage
        student_list[id]['sex'] = newsex
        student_list[id]['classname'] = newclassname
        print("修改成功")
    else:
        print("輸入有誤")
        
def show_student_list():
    print("*"*30)
    for id,value in student_list.items():
        print("學號%s 姓名%s 年齡%s 性別%s 班級%s"%(id,value['name'],value['age'],value['sex'],value['classname']))
def main():
    while True :
        menu()
        user_input = input("請輸入你要選擇操作的數字1/2/3/4/5")
        if user_input == "1":
            add_student()
        elif user_input == "2":
            delete_student()
        elif user_input == "3":
            edit_student()
        elif user_input == "4":
            show_student_list()
        elif user_input == "5":
            print("歡迎下次使用")
            break
        else:
            print("你的輸入有錯誤")
main()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章