day08-提高作業(yè)(控制臺學(xué)生管理系統(tǒng))

完成一個(gè)控制臺學(xué)生管理系統(tǒng),要求能實(shí)現(xiàn)查看所有學(xué)生的學(xué)號、姓名、年齡、電話,并且能根據(jù)學(xué)號和姓名進(jìn)行查詢,能修改學(xué)生的信息,能刪除學(xué)生信息

all_students = [
{'no':'stu001','name':'stu1','age':18,'phone':'1811111111111'},
{'no':'stu002','name':'stu2','age':20,'phone':'1811111100000'},
{'no':'stu003','name':'stu3','age':22,'phone':'1811111100011'}]

wellcome = """
========================================
歡迎進(jìn)入學(xué)生管理系統(tǒng):
   ? 1.  添加學(xué)生
   ? 2.  查看學(xué)生
   ? 3.  修改學(xué)生信息
   ? 4.  刪除學(xué)生
   ? 5.  退出
========================================
請輸入(1-5):
"""
wellcome2 = """
1. 查看所有學(xué)生
2. 按姓名查找
3. 按學(xué)號查找
4. 返回
"""

while True:
    menu =int(input(wellcome))
    if menu == 1:
        sub_menu = 1
        while sub_menu != 2:
            name = input("請輸入學(xué)生姓名:")
            age = input("請輸入學(xué)生年齡:")
            phone = input("請輸入學(xué)生電話:")
            no = 'stu%03d' % (len(all_students) + 1)
            student = {
                'no':no,
                'name':name,
                'age':int(age),
                'phone':phone
            }
            all_students.append(student)
            print("添加成功!")
            sub_menu =int(input("1. 繼續(xù)\n2. 返回\n請選擇(1-2):")) 
    elif menu == 2:
        sub_menu = int(input(wellcome2))
        while sub_menu!=4:
            if sub_menu == 1:
                for student in all_students:
                    print("學(xué)號:%s\t姓名:%s\t年齡:%d\t電話:%s" % (student["no"],student["name"],student["age"],student["phone"]))
            elif sub_menu == 2:
                name = input("請輸入要查找的姓名:")
                for student in all_students:
                    if student["name"]== name:
                        print("學(xué)號:%s\t姓名:%s\t年齡:%d\t電話:%s" % (student["no"],student["name"],student["age"],student["phone"]))
            elif sub_menu == 3:
                no = input("請輸入要查找的學(xué)號:")
                for student in all_students:
                    if student["no"]== no:
                        print("學(xué)號:%s\t姓名:%s\t年齡:%d\t電話:%s" % (student["no"],student["name"],student["age"],student["phone"]))
                        break
                else:
                    print("查無此人")
            sub_menu = int(input(wellcome2))
            
    elif menu == 3:
        sub_menu = 1
        while sub_menu != 2:
            no = input("請輸入要修改的學(xué)生學(xué)號:")
            for student in all_students:
                if student["no"]== no:
                    name = input("請輸入學(xué)生姓名:")
                    age = input("請輸入學(xué)生年齡:")
                    phone = input("請輸入學(xué)生電話:")

                    student["name"] = name
                    student["age"] = int(age)
                    student["phone"] = phone
                    break
            else:
                print("查無此人")
            print("修改成功")
            sub_menu = int(input("1. 繼續(xù)\n2. 返回\n請選擇(1-2):"))
    elif menu == 4:
        sub_menu = 1
        while sub_menu != 2:
            no = input("請輸入要?jiǎng)h除的學(xué)生學(xué)號:")
            for student in all_students[:]:
                if student["no"]== no:
                    all_students.remove(student)
                    break
            else:
                print("查無此人")
            print("刪除成功")
            sub_menu = int(input("1. 繼續(xù)\n2. 返回\n請選擇(1-2):"))
    else:
        print("Bye~")
        break
         

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容