day10作业

student management system (simple version)

# author  xu dong

student_list = []


def generator_id():
    student_id = 1
    while True:
        yield str(student_id)
        student_id += 1


re = generator_id()

while True:
    print("=================================================")
    print("♥♥♥ Welcome Hogwarts magic ! ♥♥♥".center(50, ' '))
    print("=================================================")
    menu = ['♦♦ 1 . Add the student \n',
            '♦♦ 2 . Check the student \n',
            '♦♦ 3 . Revise student information \n',
            '♦♦ 4 . Del student information \n',
            '♦♦ 5 . Exit system ']
    for i in menu:
        print(i)
    select = input('please choose number :')

    if select == '1':

        def add():
            while True:
                stu_name = input('please enter student name:')
                stu_age = input('please enter student age:')
                stu_tel = input('please enter student phone number:')
                student_info = {}
                student_info['student-id'] = next(re)
                student_info['student-name'] = stu_name
                student_info['student-age'] = stu_age
                student_info['student-tel'] = stu_tel
                student_list.append(student_info)
                print('add success !')
                select01 = input('1 continue\n2 back up')
                if select01 == '1':
                    continue
                else:
                    break
            return student_list
        add()
    elif select == '2':
        def check():
            while True:
                menu01 = ['♦♦ 1 . View all students\n',
                          '♦♦ 2 . Search by name\n',
                          '♦♦ 3 . Search by student id\n',
                          '♦♦ 4 . Back up']
                for i1 in menu01:
                    print(i1)
                select1 = input('please choose number :')
                if select1 == '1':
                    for i2 in student_list:
                        print('student-id:stu00%s  student-name:%s  student-age:%s  student-tel:%s'
                              % (i2['student-id'], i2['student-name'], i2['student-age'], i2['student-tel']))
                elif select1 == '2':
                    select_name = input('please enter your check name :')
                    for i3 in student_list:
                        if select_name == i3['student-name']:
                            print('student-id:stu00%s  student-name:%s  student-age:%s  student-tel:%s'
                                  % (i3['student-id'], i3['student-name'], i3['student-age'], i3['student-age']))
                elif select1 == '3':
                    select_id = input('please enter your check id :')
                    for i4 in student_list:
                        if int(select_id) == i4['student-id']:
                            print('student-id:stu00%s  student-name:%s  student-age:%s  student-tel:%s'
                                  % (i4['student-id'], i4['student-name'], i4['student-age'], i4['student-age']))
                elif select1 == '4':
                    break
        check()

    elif select == '3':

        def change():
            while True:
                menu02 = ['♦♦ 1 . Amend student information\n',
                          '♦♦ 2 . Back up homepage ']
                for i1 in menu02:
                    print(i1)
                select1 = input('please choose number : ')
                if select1 == '1':
                    student_id = input('please enter this student id:')
                    for i2 in student_list:
                        if int(student_id) == i2['student-id']:
                            i2['student-id'] = input('please Amend student number:')
                            i2['student-name'] = input('please Amend student name:')
                            i2['student-age'] = input('please Amend student age:')
                            i2['student-tel'] = input('please Amend student tel:')
                            print('student-id:stu00%s  student-name:%s  student-age:%s  student-tel:%s'
                                  % (i2['student-id'], i2['student-name'], i2['student-age'], i2['student-tel']))
                            print('Amend success ')
                            break
                elif select1 == '2':
                    break
        change()
    elif select == '4':
        def delete():
            while True:
                menu1 = ['♦♦ 1 . Delete by student id\n',
                         '♦♦ 2 . Delete by student name\n',
                         '♦♦ 3 . Back up homepage ']
                for i1 in menu1:
                    print(i1)
                choose = input('please choose number:')
                if choose == '1':
                    student_id = input('please enter student id:')
                    for i2 in student_list:
                        if student_id == i2['student-id']:
                            print('student-id:stu00%s  student-name:%s  student-age:%s  student-tel:%s'
                                  % (i2['student-id'], i2['student-name'], i2['student-age'], i2['student-age']))
                            student_list.remove(i2)
                            print('Delete success !')
                elif choose == '2':
                    student_name = input('please enter student name:')
                    for i3 in student_list:
                        if student_name == i3['student-name']:
                            print('student-id:stu00%s  student-name:%s  student-age:%s  student-tel:%s'
                                  % (i3['student-id'], i3['student-name'], i3['student-age'], i3['student-age']))
                            student_list.remove(i3)
                            print('Delete success !')
                elif choose == '3':
                    break
        delete()
    elif select == '5':
        select1 = input('Terminate system ?Y/N')
        if select1 == 'y':
            print('Terminate success !')
            break
        else:
            continue

你可能感兴趣的:(day10作业)