2018-09-01 學生系統

weixin_34249678發表於2018-09-01
print('  =====================')
print(" 丨 python1806管理系統  丨".center(20))
print(" 丨     1.新增學生      丨".center(20))
print(" 丨     2.檢視學生      丨".center(20))
print(" 丨     3.刪除學生      丨".center(20))
print(" 丨     4.修改資訊      丨".center(20))
print(" 丨     5.退出系統      丨".center(20))
print('  =====================')
py_system = {'students': []}
all_students = {}
new_students = {}
for x in range(10000):
    print("==================================================\
    \n主選單:1.新增學生.2.檢視學生.3.刪除學生.4.修改資訊.5退出\
    \n==================================================")
    num1 = input("請輸入選項:")
    all_students = py_system['students'].copy()
    if num1 == '1':
        print("  ------------------".center(19))
        print("   新增學生資訊  ".center(17))
        print("  ------------------".center(19))
        name1 = input("請輸入姓名:")
        age1 = input("請輸入年齡:")
        ele1 = input("請輸入號碼:")
        student1 = {'姓名': name1, '年齡': age1, '電話': ele1}
        py_system['students'].append(student1)
        print("----------------------")
        print("  新增成功 返回主選單 ".center(15))
        print("----------------------")

    elif num1 == '2':
        if py_system['students'] == []:
            print("------------------")
            print("資訊為空!".center(15))
            print("------------------")
        else:
            print("\n")
            print("  ------------------".center(19))
            print("       使用者資訊      ".center(17))
            print("  ------------------".center(19))
            print(py_system['students'])
            print("\n")

    elif num1 == '3':
        if all_students == []:
            print("---------------------")
            print("資訊為空 請新增學生資訊!".center(11))
            print("---------------------")
        for new_students in all_students[:]:
            name2 = input("查詢需要刪除的姓名:")
            if new_students['姓名'] == name2:
                print("\n")
                print("----------------")
                print(("%s同學的資訊" % (name2)).center(11))
                print("----------------")
                print(new_students)
                print("\n")
                print("是否確認刪除?(Y/N)")
                n = input()
                if n == 'y' or n == 'Y':
                    py_system['students'].remove(new_students)
                    print("-------------------")
                    print('刪除成功!!!'.center(15))
                    print("-------------------")
                elif n == 'n' or n == 'N':
                    print("返回主選單")
                    print("\n")
                    break
                else:
                    print("輸入錯誤!")
            else:
                print("-------------------")
                print("     資訊未查詢      ")
                print("-------------------")
                continue

    elif num1 == '4':
        if all_students == []:
            print("---------------------")
            print("資訊為空 請新增學生資訊!".center(11))
            print("---------------------")
        name3 = input("輸入姓名修改:")
        for new_students in all_students[:]:
            if new_students['姓名'] == name3:
                print('\n')
                print('  ====================')
                print(" 丨 python1806管理系統 丨   ".center(20))
                print(" 丨   修  改  信  息   丨 ".center(20))
                print(" 丨     1.修改資訊     丨   ".center(20))
                print(" 丨     2.返回選單     丨   ".center(20))
                print('  ====================')
                print("----------------")
                print(("%s同學的資訊" % (name3)).center(11))
                print("----------------")
                print(new_students)
                print("-----------------------------------------------------")
                num2 = int(input("修改資訊:1.修改資訊 2.返回主選單\n請輸入選項:"))
                if num2 == 1:
                    print('========================================================')
                    print('修改資訊:1.修改姓名.2.修改年齡.3.修改電話.4.返回主選單')
                    print('========================================================')
                    num3 = int(input("請輸入選項:"))
                    if num3 == 1:
                        name4 = input("姓名修改為:")
                        for new_students in all_students[:]:
                            if new_students['姓名'] == name3:
                                new_students['姓名'] = name4
                                print('修改成功!!!')
                                print(new_students)
                        break
                    elif num3 == 2:
                        age2 = input("年齡修改為:")
                        for new_students in all_students[:]:
                            if new_students['姓名'] == name3:
                                new_students['年齡'] = age2
                                print('修改成功!!!')
                                print(new_students)
                        break
                    elif num3 == 3:
                        ele1 = input("年齡修改為:")
                        for new_students in all_students[:]:
                            if new_students['姓名'] == name3:
                                new_students['電話'] = ele1
                                print('修改成功!!!')
                                print(new_students)
                        break
                    elif num3 == 4:
                        print("-------------------")
                        print("     返回主選單     ")
                        print("-------------------")
                else:
                    break
            elif new_students['姓名'] != name3:
                print("%s尚未新增資訊資料!" % name3)
    elif num1 == '5':
        print("已退出")
        break
    else:
        print("輸入錯誤!!請重新輸入!!")
        continue

相關文章