python

学生管理系统

2018-07-29  本文已影响48人  堪怜咏絮才

学生管理系统

def ShowInformation():
    print('*'*30                                    )
    print('Welcome to the student management system')
    print("1、Add student's information            ")
    print('2、Student information query            ')
    print("3、Delete student's information         ")
    print("4、Modify student's information         ")
    print("5、Iterate through student's information")
    print('6、Exit system                          ')
    print('*'*30                                    )
students_info = {}
number = 0
key_all_students = 'student'
key_name = 'student_name'
key_age = 'age'
key_tel = 'tel'
key_id = 'id'
while True:
    ShowInformation()
    Option = input('Please select the project you want to operate on!')
    if Option == '6':
        break
    if Option == '1':
        print('You chose to add the student information project!')
        add_name = input("Please enter the student's name:")
        add_age = input("Please enter the student's age:")
        add_tel = input("Please enter the student's telephone number:")
        number += 1
        add_id = 'Python1805'+str(number).rjust(3,'0')
        add_student = {key_name: add_name, key_age: add_age, key_tel: add_tel, key_id: add_id}
        all_students = students_info.get(key_all_students)

        if all_students == None:
            all_student = []
        all_students.append(add_student)
        students_info[key_all_students] = all_students
        print('Successfully add student %s!' % add_name)
        print(students_info)
        print('1:Continue to add!\n'
              'Other:Go back!')

        Choose = input('Please select the operation you want!')

        if Choose != '1':
            break
        continue
    if Option == '2':
        print('You chose to student information query project!')
        print('1.View all student information!')
        print('2.View student information by name!')
        print('3.View student information according to the student number!')
        print('4.Go back!')
        find_input = input('Please select the project you want to operate on!')
        if find_input == '4':
            continue

        all_students = students_info.get(key_all_students)
        if not all_students:
            print('There are no students in the system!!')
            continue
        if find_input == '1':
            for student in all_students:
                print('name:%s,age:%s,tel:%s,id:%s' % \
                      (student[key_name], student[key_age], student[key_tel], student[key_id]))

        # ==Search by name==
        if find_input == '2':
            find_name = input('Please enter the name of the student you want to see:')
            flag = True
            for student in all_students:
                if find_name == student[key_name]:
                    print(student)
                    flag = False
            if flag:
                print('Information about the student could not be found!')

        # ==Search by id====
        if find_input == '3':
            find_id = input('Please enter the student id you want to see:')
            flag = True
            for student in all_students:
                if find_id == student[key_id]:
                    print(student)
                    flag = False
                    break
            if flag:
                print('Information about the student could not be found!')
        continue
    if Option == '3':
        print("You choose to delete student's information project!")
        while True:
            print('1.Delete by name!')
            print('2.Student id deletion!')
            print('3.Go back!')
            del_input = input('Please select the project you want to operate on!')
            if del_input == '3':
                break

            all_students = students_info.get(key_all_students)
            if not all_students:
                print('The system has no students!')
                break

            if del_input == '1':
                del_name = input('Enter the name of the student to be deleted!')
                del_students = []
                for student in all_students:
                    if del_name == student[key_name]:
                        del_students.append(student)
                if not len(del_students):
                    print('No information about the student was found!')
                    continue

                index = 0
                for student in del_students:
                    print(index, student)
                    index += 1

                del_num = input('Please select the student number you want to delete!')
                del_student = del_students[int(del_num)]

                students_info[key_all_students].remove(del_student)
                print('Successfully delete!')
    if Option == '4':
        print("You choose to modify student's information project!")
        print("1.Change the student's name!")
        print("2.Modify the student's age!")
        print("3.Modify the student's telephone number!")
        print("4.Go back!")
        all_students = students_info.get(key_all_students)

        while True:
            if not len(all_students):
                modify_info = input('Please select the project you want to operate on!')
                if modify_info == '4':
                    break

                student_id = input('Please enter the student id you want to change!')

                if modify_info == '1':
                    for student in all_students:
                        if student[key_id] == student_id:
                            modify_name = input('Please enter the modified name!')
                            student[key_name] = modify_name
                    print('1.Continue to modify!2.Go back!')
                    Choose = input('Please enter your selection!')
                    if Choose != '1':
                        break

                if modify_info == '2':
                    for student in all_students:
                        if student[key_id] == student_id:
                            modify_age = input('Please enter the modified age!')
                            student[key_age] = modify_age
                    print('1.Continue to modify!2.Go back!')
                    Choose = input('Please enter your selection!')
                    if Choose != '1':
                        break

                if modify_info == '3':
                    for student in all_students:
                        if student[key_id] == student_id:
                            modify_tel = input('Please enter the modified telephone number!')
                            student[key_tel] = modify_tel
                    print('1.Continue to modify!2.Go back!')
                    Choose = input('Please enter your selection!')
                    if Choose != '1':
                        break

    if Option == '5':
        print("You choose to iterate through student's information project")
        all_students = students_info.get(key_all_students)
        while True:
            if not len(all_students):
                print('The system has no students!')
                break
            else:
                for student in all_students:
                    print(student)
            break
上一篇 下一篇

猜你喜欢

热点阅读