posted on 2023-06-06 12:10 read(1038) comment(0) like(5) collect(0)
Table of contents
1. Definition of main function
7. Count the total number of students
8. Display all student information
For this system, I use the window11 system, the version of the python interpreter used : python3.8, it is recommended to do it in pycharm
Writing. Based on the mastery of the basic knowledge of Python, a comprehensive analysis of the student performance management system, step by step explanation, hope to
Help to those in need.
Aiming at the convenience for students to inquire about their own grades, a simple class learning performance management system was independently written. Among them, the student performance management system mainly includes the functions of entering student information, finding student information, deleting student information, modifying student information, sorting student information, counting the total number of students, and displaying student information. The student information entered includes student number, name, C language programming grades, Python grades, Java grades, and grade points; there are two types of querying student information: searching by student number and searching by name; deleting student information is to enter the student number to search , after the student information is found, delete the student information; modify the student information after entering the student number, and then modify the student information after querying the student information; the sorting method of sorting the student information can be selected in ascending order or descending order, and you can choose to press C Sorting language programming grades, Python grades, Java grades, and grade points; counting the total number of students is the output information of how many students there are in the information management system. The student performance management system is difficult to say, easy to say, and it is not a small challenge for beginners. For this system, its functions and so on are many, so we need to have a general idea. Let's do it better.
serial number | Function |
0 | Exit system |
1 | Enter student information insert() |
2 | Find student information search() |
3 | Delete student information delete() |
4 | Modify student information modity() |
5 | sort sort() |
6 | Count the total number of students total() |
7 | Display all student information show() |
The general style is as shown in the figure:
code:
- import os
- def main ():
- while True:
- menu() //调用菜单函数
- choice=int(input('请选择:'))
- if choice in [0,1,2,3,4,5,6,7]:
- if choice==0:
- answer = input ('请确定要退出系统?y/n:')
- if answer == 'y' or answer == 'Y':
- print ('谢谢你的使用')
- break
- else:
- continue
- elif choice==1:
- insert()
- elif choice==2:
- search ()
- elif choice==3:
- delete()
- elif choice==4:
- modify()
- elif choice==5:
- sort()
- elif choice==6:
- total()
- elif choice==7:
- show()
- else:
- print('请正确输入数字!')
- def menu():
- print ('=========================学生成绩管理系统=========================')
- print ('----------------------------功能模块----------------------------')
- print ('\t\t\t\t\t\t1.录入学生信息')
- print ('\t\t\t\t\t\t2.查找学生信息')
- print ('\t\t\t\t\t\t3.删除学生信息')
- print ('\t\t\t\t\t\t4.修改学生信息')
- print ('\t\t\t\t\t\t5.排序')
- print ('\t\t\t\t\t\t6.统计学生总人数')
- print ('\t\t\t\t\t\t7.显示所有学生信息')
- print ('\t\t\t\t\t\t0.退出系统')
- print ('-------------------------------------------------------------')
-
- if __name__ == '__main__': //程序开始运行
- main()
The user operates according to the number corresponding to the input function module, and returns to the main page again after the function is used. If the user enters the number 0, then enter y according to the prompt to exit the system, otherwise continue to return to the main interface
- def main ():
- while True:
- menu()
- choice=int(input('请选择:'))
- if choice in [0,1,2,3,4,5,6,7]:
- if choice==0:
- answer = input ('请确定要退出系统?y/n:')
- if answer == 'y' or answer == 'Y':
- print ('谢谢你的使用')
- break
- else:
- continue
- elif choice==1:
- insert()
- elif choice==2:
- search ()
- elif choice==3:
- delete()
- elif choice==4:
- modify()
- elif choice==5:
- sort()
- elif choice==6:
- total()
- elif choice==7:
- show()
- else:
- print('请正确输入数字!')
Enter student information function code part, the function implemented in this function is to enter student information, including student number, name, C language score, Python score, Java score, and write it into a file, each line is a student's information storage.
- def insert(): //插入学生信息功能
- stu_lst = []
- while True:
- no=int(input('请输入学号(例如1001):'))
- if not no:
- break
- name=input('请输入姓名:')
- if not name:
- break
- try:
- c = int (input ('请输入C语言成绩:'))
- python = int (input ('请输入Python的成绩:'))
- java = int (input ('请输入Java的成绩:'))
- except:
- print('输入无效,请重新输入!')
- continue
- student={'id':no,'name':name,'C语言':c,'Python':python,'Java':java}
- stu_lst.append(student)
- save (stu_lst)
- print ('信息录入成功!')
- stu_lst.clear()
- choice=input('是否继续?y/n:')
- if choice=='y' or choice=='Y':
- continue
- else:
- break
-
- def save(lst): //存储列表数据
- try:
- stu_txt=open(filename,'a',encoding='utf-8')
- except:
- stu_txt=open(filename,'w',encoding='utf-8')
- for item in lst:
- stu_txt.write(str(item)+'\n')
- stu_txt.close()
Delete the student information function code part, the main function of this function is to perform the delete operation, enter the student number to search, and delete the student information after finding the student information.
- def delete(): //删除学生信息功能
- while True:
- student_id=int(input('请输入学生的id:'))
- if student_id:
- if os.path.exists(filename):
- with open(filename,'r',encoding='utf-8') as file:
- student_old = file.readlines()
- else:
- student_old=[]
- flag=False
- if student_old:
- with open(filename,'w',encoding='utf-8') as files:
- for item in student_old:
- d = dict (eval (item))
- if d['id']!=student_id:
- files.write(str(d)+'\n')
- else:
- flag=True
- if flag:
- print (f'学号为{student_id}的学生信息已删除!')
- else:
- print (f'没有找到id为{student_id}的学生信息')
- else:
- print('无学生记录')
- break
- show()
- choice = input ('是否继续?y/n:')
- if choice == 'y':
- continue
- else:
- break
- def show(): //显示文本中的数据
- student_lst=[]
- if os.path.exists(filename):
- with open(filename,'r',encoding='utf-8') as file:
- student=file.readlines()
- for item in student:
- student_lst.append(eval(item))
- if student_lst:
- show_student(student_lst)
- else:
- print('暂未保存学生数据!')
Modify the code part of the student information function. The main function of this function is to modify the student information. After entering the student number and querying the student information, modify the grades of each subject of the student.
- def modify():
- show()
- if os.path.exists(filename):
- with open(filename,'r',encoding='utf-8') as file:
- student_lst=file.readlines()
- else:
- return
- student_id=int(input('请输入学生id:'))
- with open(filename,'w',encoding='utf-8') as file1:
- for item in student_lst:
- d = dict (eval (item))
- if d ['id'] == student_id:
- print(f'已经找到id为{student_id}的学生')
- while True:
- try:
- d ['name'] = input ('请输入学生姓名:')
- d ['C语言'] = int (input ('请输入C语言成绩:'))
- d ['Python'] = int (input ('请输入Python的成绩:'))
- d ['Java'] = int (input ('请输入Java的成绩:'))
- except:
- print('输入的信息有误,重新输入!!')
- else:
- break
- file1.write(str(d)+'\n')
- print('修改信息成功!!!!!!!')
- else:
- file1.write(str(d)+'\n')
- switch = input ('是否要修改信息?y/n:')
- if switch == 'y':
- modify()
Query the student information function code part. The main function of this function is to query by student number and name. If there is no such person, it will output "there is no such student information in the l list".
- def search(): //定义查找学生信息函数
- search_qurry=[]
- while True:
- id=''
- name=''
- if os.path.exists(filename):
- choice = int (input ('Id查询请按1,名字查询请按2:'))
- if choice == 1:
- id=int(input('请输入学生id:'))
- elif choice==2:
- name=input('请输入学生姓名:')
- else:
- print('输入有误,重新输入!')
- search()
- with open(filename,'r',encoding='utf-8') as file:
- student_lst=file.readlines()
- for item in student_lst:
- d = dict (eval (item))
- if id!='':
- if d['id']==id:
- search_qurry.append(d)
- elif name!='':
- if d['name']==name:
- search_qurry.append(d)
- show_student(search_qurry)
- search_qurry.clear()
- a=input('是否继续查找?y/n:')
- if a=='y':
- continue
- else:
- break
-
- def show_student(lst): //显示学生成绩列表
- if len(lst)==0:
- print('列表中无此学生的信息')
- return
- student_title='{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}'
- print(student_title.format('ID','姓名','C语言成绩','Python成绩','Java成绩','绩点'))
- student_data='{:^6}\t{:^12}\t{:^8}\t{:^8}\t{:^8}\t{:^8}'
- for item in lst:
- print(student_data.format(item.get('id'),item.get('name'),item.get('C语言'),item.get('Python'),item.get('Java'),round((int(item.get('C语言'))+int(item.get('Python'))+int(item.get('Java'))-180)/30,2)))
- print ('\n')
The function of sorting student information is to sort the student information. The sorting method can be selected in ascending order and descending order. The sorting condition can be sorted by English C language, Python, Java scores and grade points converted from the three grades.
- def sort():
- show()
- if os.path.exists(filename):
- with open(filename,'r',encoding='utf-8')as file:
- student_lst=file.readlines()
- student_new=[]
- for item in student_lst:
- d=dict(eval(item))
- student_new.append(d)
- else:
- return
- switch=input('排序方式(0.升序,1.降序)')
- if switch=='0':
- switch_bool=False
- elif switch=='1':
- switch_bool=True
- else:
- print('输入错误!')
- sort()
- choice=input('请选择排序方式(1.C语言成绩,2.Python成绩,3.Java成绩,4.绩点)')
- if choice=='1':
- student_new.sort(key=lambda x:int(x['C语言']),reverse=switch_bool)
- elif choice=='2':
- student_new.sort (key=lambda x: int (x ['Python']), reverse=switch_bool)
- elif choice=='3':
- student_new.sort (key=lambda x: int (x ['Java']), reverse=switch_bool)
- elif choice=='4':
- student_new.sort (key=lambda x: round((int (x ['C语言'])+int (x ['Python'])+int (x ['Java'])),2), reverse=switch_bool)
- else:
- print('选择错误!重新输入')
- sort()
- show_student(student_new)
The function code part of counting the total number of students, this function is mainly to output the information of several students in the data text file stored in the information management system.
- def total():
- if os.path.exists(filename):
- with open(filename,'r',encoding='utf-8') as file:
- students=file.readlines()
- if students:
- print('系统内有{}个学生'.format(len(students)))
- else:
- print('系统内无学生记录!')
- else:
- print('暂未保存学生信息!')
Display student information function code part, this function is to display all the student information stored in the file (student number, name, C language score, Python score, Java score, grade point)
- def show_student(lst):
- if len(lst)==0:
- print('列表中无此学生的信息')
- return
- student_title='{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}'
- print(student_title.format('ID','姓名','C语言成绩','Python成绩','Java成绩','绩点'))
- student_data='{:^6}\t{:^12}\t{:^8}\t{:^8}\t{:^8}\t{:^8}'
- for item in lst:
- print(student_data.format(item.get('id'),item.get('name'), item.get('C语言'),item.get('Python'),item.get('Java'),round((int(item.get('C语言'))+int(item.get('Python'))+int(item.get('Java'))-180)/30,2)))
- print ('\n')
Project packaging:
install third-party modules: 1, press win+R, enter cmd, open the cmd command interface,
Online installation mode: pip install Pyinstaller
2, perform the packaging operation
pyinstaller -F E:\PyhonProject\Chap1\system.py
If there are special requirements, the code can be changed after copying. I believe that after reading it, I will have a better understanding of Python knowledge, and hope to have a certain foundation for beginners and beginners. Thanks!
Author:Abstract
link:http://www.pythonblackhole.com/blog/article/80301/d5770e7297b9c0932332/
source:python black hole net
Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.
name:
Comment content: (supports up to 255 characters)
Copyright © 2018-2021 python black hole network All Rights Reserved All rights reserved, and all rights reserved.京ICP备18063182号-7
For complaints and reports, and advertising cooperation, please contact vgs_info@163.com or QQ3083709327
Disclaimer: All articles on the website are uploaded by users and are only for readers' learning and communication use, and commercial use is prohibited. If the article involves pornography, reactionary, infringement and other illegal information, please report it to us and we will delete it immediately after verification!