In this article, we share examples of Python implementation of the specific code of the student information management system for your reference, the details are as follows
Request a description:
Student information includes: student number, name, age, gender, date of birth, address, phone number, E-mail and so on. Try to design a student information management system that provides the following basic functions:
- The system works in menu mode
- Student information entry function (student information is saved in a file) --- Input
- Student Information Viewing Function --- Output
- Queries, sorting functions -- algorithms
1. Search by student number
2. Search by name
- Deletion and modification of student information (optional)
The basic idea with the previously written piece of the book lending system, will not repeat here.
Directly on the code, the code is as follows:
import os class Student(object): def __init__(self, sid, name, age=None, gender=None, birth=None, address=None, tel=None, mail=None): = sid = name = age = gender = birth = address = tel = mail def __str__(self): return "%s:%s:%s:%s:%s:%s:%s:%s" %(, , , , , , , ) class StudentManage(object): students = [] def __init__(self): filename = '' if (filename): with open(filename) as f: for line in f: info = (':') studentObj = Student(*info) (studentObj) print("Loading cached student information was successful.") else: print("Uncached student information!") def add(self): sid = input("School number: ") name = input("Name: ") age = input("Age: ") gender = input("Sex (1-male 2-female):") birth = input("Date of birth (dd/mm/yyyy): ") address = input("Address: ") tel = input("Contact number: ") mail = input("E-mail: ") stu = Student(sid, name, age, gender, birth, address, tel, mail) (stu) print("Entry of student [%s] information was successful." %(name)) def show(self): print("Student Information Display".center(50, '*')) for student in : print('-' * 50) print(str(student)) def search(self, key, value): if key in ['sid', 'name']: for student in : if getattr(student, key) == value: print(str(student)) else: print("No eligible student information found!") else: print("The system only supports queries based on [student number] and [name]!") def sort(self, key): # Sort by specified key value sorted_students = sorted(, key=lambda x: int(getattr(x, key)) if x else None) for student in sorted_students: print(student) def delete(self, key, value): if key in ['sid', 'name']: for student in : if getattr(student, key) == value: (student) print("Delete student information with attribute value [%s] of [%s]" % (key, value)) else: print("No eligible student information found!") else: print("The current system only supports deletion based on [student number] and [name]!") def modify(self, key, oldvalue, newvalue): if key in ['sid', 'name']: for student in : if getattr(student, key) == oldvalue: setattr(student, key, newvalue) print("Modifying student information with attribute value [%s] of [%s] to [%s] was successful" % (key, oldvalue, newvalue)) else: print("No eligible student information found!") else: print("The current system only supports changes based on [student number] and [name]!") def save(self): filename = '' f = open(filename, 'w') for student in : (str(student) + '\n') print("Writing student information was successful!") () def main(): manager = StudentManage() while True: menu = """ Student Information Management System 1. student information entry 2. student information browsing 3. student information query 4. Sorting student information 5. Deletion of student information 6. Modify Student Information 7. Exit Please enter the correct selection: """ choice = input(menu) if choice == '1': () () elif choice == '2': () elif choice == '3': key = input("consult (a document etc)(sid-According to the school number, name-By name): ") value = input("Query value: ") (key, value) elif choice == '4': key = input("arrange in order(sid-According to the school number, age-Based on age): ") (key) elif choice == '5': key = input("removing(sid-According to the school number, name-By name): ") value = input("Deleted attribute values: ") (key, value) elif choice == '6': key = input("modifications(sid-According to the school number, name-By name): ") value1 = input("Old attribute value: ") value2 = input("New attribute value: ") (key, value1, value2) elif choice == '7': exit(0) else: print("Please enter the correct selection!") main()
Once run, the available function menu keys are output as follows:
Here's the basic functional implementation:
1. Enter student information
2. Browse student information
3. Searching for designated student information
4. Sort student information (can be sorted by school number or age from smallest to largest)
5. Delete the information of the specified student
6. Modification of specified student information (modification of student number or name)
You can see that the student information will change after the operation:
Then after typing 7 it will exit the system.
Above is a simple student information management system implemented through Python.
This is the whole content of this article.