Hello ~ Hello, I'm Cha Cha! A little friend asked me before that I want to make a school student management system, so let's make a simple student management system today!
1, The first is the development environment we need
-
Python 3.8
-
Pycharm 2021.2
2, Knowledge points we will involve
-
Python basic syntax
-
Basic data types and structures
-
Basic logic control statement
-
Practical small projects
3, Then I started typing the code
Step 1: make the interface of student management system
-
Start the program, display the welcome interface of the information management system, and display the function menu (print)
-
The user selects different functions (input) with numbers
-
Perform different functions according to function selection (if judge multi branch selection)
-
It is necessary to record the student's name, Chinese score, mathematics score, English score and total score (input, the data container stores the input student information)
-
If the specified student information is queried, the user can choose to modify or delete the information (logic in multi branch selection)
-
Load or save data on entry or exit (file operation)
""" str_info = """************************************************** Welcome to [student information management system] V1.0 Please select the operation you want to perform 1. New student information 2. Show all information 3. Query student information 4. Delete student information 5. Modify student information 0. Exit the system **************************************************""" while True: # 1. Start the program, display the welcome interface of the information management system, and display the function menu (print) print(str_info) # 2. The user selects different functions (input) with numbers action = input('Please select the operation you want to perform(Enter number):') if action == '1': print('1. New student information') elif action == '2': print('2. Show all information') elif action == '3': print('3. Query student information') elif action == '4': print('4. Delete student information') elif action == '5': print('5. Modify student information') elif action == '0': print('0. Exit the system') break else: print('Please enter the correct option!')
effect:
************************************************** Welcome to [student information management system] V1.0 Please select the operation you want to perform 1. New student information 2. Show all information 3. Query student information 4. Delete student information 5. Modify student information 0. Exit the system **************************************************
Step 2: create new student information
It is necessary to record the student's name, Chinese score, mathematics score, English score and total score (input, the data container stores the input student information)
name = input('Please enter the student's name:') chinese = int(input('Please enter the student's language score:')) math = int(input('Please enter the student's math score:')) english = int(input('Please enter the student's English score:')) total = chinese + math + english # What data container is better to accept? Store information and take values in dictionary students = [ {'name': name, 'chinese': chinese, 'math': math, 'english': english, 'total': total} ] print(students)
Step 3: display all student information
students = [ {'name': 'Zhengxin', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, {'name': 'Zhang San', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, {'name': 'Li Si', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, {'name': 'Wang Wu', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, ] print('full name\t language\t mathematics\t English\t Total score') for stu in students: # print(stu) print(f'{stu["name"]}\t{stu["chinese"]}\t\t{stu["math"]}\t\t{stu["english"]}\t\t{stu["total"]}')
Step 4: query student information
students = [ {'name': 'Zhengxin', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, {'name': 'Zhang San', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, {'name': 'Li Si', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, {'name': 'Wang Wu', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, ] # 5. If the specified student information is queried, the user can choose to modify or delete the information (logic in multi branch selection) name = input('Please enter the name of the student you want to query:') # Go through all the students first for stu in students: # If the conditions are met, it is queried if name == stu['name']: print('full name\t language\t mathematics\t English\t Total score') print(f'{stu["name"]}\t{stu["chinese"]}\t\t{stu["math"]}\t\t{stu["english"]}\t\t{stu["total"]}') # Once the query is found, stop the query break else: # Can't find print('The student does not exist, Please check that the name is entered correctly!')
Step 5: modify student information
import pprint students = [ {'name': 'Zhengxin', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, {'name': 'Zhang San', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, {'name': 'Li Si', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, {'name': 'Wang Wu', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, ] # 5. If the specified student information is queried, the user can choose to modify or delete the information (logic in multi branch selection) name = input('Please enter the name of the student you want to modify:') # Go through all the students first for stu in students: # If the conditions are met, the student is found # Found the students who need to be modified if name == stu['name']: # If you don't want to modify it, just press enter print('(If you don't want to modify it,Direct enter!)') name = input('Please re-enter the student's name:') chinese = input('Please re-enter the student's language score:') math = input('Please re-enter the student's math score:') english = input('Please re-enter the student's English score:') # total = chinese + math + english # The user can only modify after entering data if name: stu['name'] = name if chinese: stu['chinese'] = int(chinese) if math: stu['math'] = int(math) if english: stu['english'] = int(english) stu['total'] = stu['chinese'] + stu['math'] + stu['english'] break else: # Can't find print('The student does not exist, Please check that the name is entered correctly!') pprint.pprint(students)
Step 6: delete student information
import pprint students = [ {'name': 'Zhengxin', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, {'name': 'Zhang San', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, {'name': 'Li Si', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, {'name': 'Wang Wu', 'chinese': 59, 'math': 59, 'english': 59, 'total': 177}, ] # 5. If the specified student information is queried, the user can choose to modify or delete the information (logic in multi branch selection) name = input('Please enter the name of the student you want to delete:') # Go through all the students first for stu in students: # Find students if name == stu['name']: # Delete student students.remove(stu) break else: # Can't find print('The student does not exist, Please check that the name is entered correctly!') pprint.pprint(students)
Then put them together to complete our simple student management system!
5, Last code
import json str_info = """************************************************** Welcome to [student information management system] V1.0 Please select the operation you want to perform 1. New student information 2. Show all information 3. Query student information 4. Delete student information 5. Modify student information 0. Exit the system **************************************************""" # read file with open('students.json', mode='r', encoding='utf-8') as f: students_str = f.read() students = json.loads(students_str) while True: # 1. Start the program, display the welcome interface of the information management system, and display the function menu (print) print(str_info) # 2. The user selects different functions (input) with numbers action = input('Please select the operation you want to perform(Enter number):') if action == '1': print('1. New student information') name = input('Please enter the student's name:') chinese = int(input('Please enter the student's language score:')) math = int(input('Please enter the student's math score:')) english = int(input('Please enter the student's English score:')) total = chinese + math + english # New student stu = {'name': name, 'chinese': chinese, 'math': math, 'english': english, 'total': total} students.append(stu) elif action == '2': print('2. Show all information') print('full name\t language\t mathematics\t English\t Total score') for stu in students: print(f'{stu["name"]}\t{stu["chinese"]}\t\t{stu["math"]}\t\t{stu["english"]}\t\t{stu["total"]}') elif action == '3': print('3. Query student information') name = input('Please enter the name of the student you want to query:') # Go through all the students first for stu in students: # If the conditions are met, it is queried if name == stu['name']: print('full name\t language\t mathematics\t English\t Total score') print(f'{stu["name"]}\t{stu["chinese"]}\t\t{stu["math"]}\t\t{stu["english"]}\t\t{stu["total"]}') # Once the query is found, stop the query break else: # Can't find print('The student does not exist, Please check that the name is entered correctly!') elif action == '4': print('4. Delete student information') name = input('Please enter the name of the student you want to delete:') # Go through all the students first for stu in students: # Find students if name == stu['name']: # Delete student students.remove(stu) break else: # Can't find print('The student does not exist, Please check that the name is entered correctly!') elif action == '5': print('5. Modify student information') name = input('Please enter the name of the student you want to modify:') # Go through all the students first for stu in students: # If the conditions are met, the student is found # Found the students who need to be modified if name == stu['name']: # If you don't want to modify it, just press enter print('(If you don't want to modify it,Direct enter!)') name = input('Please re-enter the student's name:') chinese = input('Please re-enter the student's language score:') math = input('Please re-enter the student's math score:') english = input('Please re-enter the student's English score:') # total = chinese + math + english # The user can only modify after entering data if name: stu['name'] = name if chinese: stu['chinese'] = int(chinese) if math: stu['math'] = int(math) if english: stu['english'] = int(english) stu['total'] = stu['chinese'] + stu['math'] + stu['english'] break else: # Can't find print('The student does not exist, Please check that the name is entered correctly!') elif action == '0': print('0. Exit the system') with open('students.json', mode='w', encoding='utf-8') as f: # Convert list objects into string ascii encoding students_str = json.dumps(students, ensure_ascii=False) f.write(students_str) print(students_str) break else: print('Please enter the correct option!')
In fact, the step-by-step operation is still very simple. As long as the ideas and steps are sorted out, we can make a management system by ourselves step by step. Many students probably don't know that we can use Python to make the school management system. Python has a wide range of applications, so let's learn it. A little knowledge every day will become the great God of Python sooner or later!
Like to remember likes, comments and collections~