News from this site

 Rental advertising space, please contact the webmaster if you need cooperation


+focus
focused

classification  

no classification

tag  

no tag

date  

2024-11(8)

Python:学习成绩管理系统

posted on 2023-06-06 12:10     read(1038)     comment(0)     like(5)     collect(0)


Table of contents

foreword

1. Demand analysis

1. Concept design

2. Flow chart design

3. Main interface design

2. Function realization

1. Definition of main function

2. Enter student information

(1) Function realization

(2) Output interface

3. Delete student information

(1) Function realization

(2) Output interface

4. Modify student information

(1) Function realization

(2) Output interface

5. Find student information

(1) Function realization

(2) Output interface 

6. Sorting

(1) Function realization

(2) Output interface

7. Count the total number of students

(1) Function realization

(2) Output interface

8. Display all student information

(1) Function realization

(2) Output interface

3. Project packaging 

Four. Summary


foreword

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.

1. Demand analysis

1. Concept design

        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.

2. Process analysis

serial numberFunction
0Exit system
1Enter student information insert()
2Find student information search()
3Delete student information delete()
4Modify student information modity()
5sort sort()
6Count the total number of students total()
7Display all student information show()

3. Main interface design

The general style is as shown in the figure:

 code:

  1. import os
  2. def main ():
  3. while True:
  4. menu() //调用菜单函数
  5. choice=int(input('请选择:'))
  6. if choice in [0,1,2,3,4,5,6,7]:
  7. if choice==0:
  8. answer = input ('请确定要退出系统?y/n:')
  9. if answer == 'y' or answer == 'Y':
  10. print ('谢谢你的使用')
  11. break
  12. else:
  13. continue
  14. elif choice==1:
  15. insert()
  16. elif choice==2:
  17. search ()
  18. elif choice==3:
  19. delete()
  20. elif choice==4:
  21. modify()
  22. elif choice==5:
  23. sort()
  24. elif choice==6:
  25. total()
  26. elif choice==7:
  27. show()
  28. else:
  29. print('请正确输入数字!')
  30. def menu():
  31. print ('=========================学生成绩管理系统=========================')
  32. print ('----------------------------功能模块----------------------------')
  33. print ('\t\t\t\t\t\t1.录入学生信息')
  34. print ('\t\t\t\t\t\t2.查找学生信息')
  35. print ('\t\t\t\t\t\t3.删除学生信息')
  36. print ('\t\t\t\t\t\t4.修改学生信息')
  37. print ('\t\t\t\t\t\t5.排序')
  38. print ('\t\t\t\t\t\t6.统计学生总人数')
  39. print ('\t\t\t\t\t\t7.显示所有学生信息')
  40. print ('\t\t\t\t\t\t0.退出系统')
  41. print ('-------------------------------------------------------------')
  42. if __name__ == '__main__': //程序开始运行
  43. main()

2. Function realization

1. Definition of main function

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

  1. def main ():
  2. while True:
  3. menu()
  4. choice=int(input('请选择:'))
  5. if choice in [0,1,2,3,4,5,6,7]:
  6. if choice==0:
  7. answer = input ('请确定要退出系统?y/n:')
  8. if answer == 'y' or answer == 'Y':
  9. print ('谢谢你的使用')
  10. break
  11. else:
  12. continue
  13. elif choice==1:
  14. insert()
  15. elif choice==2:
  16. search ()
  17. elif choice==3:
  18. delete()
  19. elif choice==4:
  20. modify()
  21. elif choice==5:
  22. sort()
  23. elif choice==6:
  24. total()
  25. elif choice==7:
  26. show()
  27. else:
  28. print('请正确输入数字!')

2. Enter student information

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.

(1) Function realization

  1. def insert(): //插入学生信息功能
  2. stu_lst = []
  3. while True:
  4. no=int(input('请输入学号(例如1001):'))
  5. if not no:
  6. break
  7. name=input('请输入姓名:')
  8. if not name:
  9. break
  10. try:
  11. c = int (input ('请输入C语言成绩:'))
  12. python = int (input ('请输入Python的成绩:'))
  13. java = int (input ('请输入Java的成绩:'))
  14. except:
  15. print('输入无效,请重新输入!')
  16. continue
  17. student={'id':no,'name':name,'C语言':c,'Python':python,'Java':java}
  18. stu_lst.append(student)
  19. save (stu_lst)
  20. print ('信息录入成功!')
  21. stu_lst.clear()
  22. choice=input('是否继续?y/n:')
  23. if choice=='y' or choice=='Y':
  24. continue
  25. else:
  26. break
  27. def save(lst): //存储列表数据
  28. try:
  29. stu_txt=open(filename,'a',encoding='utf-8')
  30. except:
  31. stu_txt=open(filename,'w',encoding='utf-8')
  32. for item in lst:
  33. stu_txt.write(str(item)+'\n')
  34. stu_txt.close()

(2) Output interface

3. Delete student information

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.

(1) Function realization

  1. def delete(): //删除学生信息功能
  2. while True:
  3. student_id=int(input('请输入学生的id:'))
  4. if student_id:
  5. if os.path.exists(filename):
  6. with open(filename,'r',encoding='utf-8') as file:
  7. student_old = file.readlines()
  8. else:
  9. student_old=[]
  10. flag=False
  11. if student_old:
  12. with open(filename,'w',encoding='utf-8') as files:
  13. for item in student_old:
  14. d = dict (eval (item))
  15. if d['id']!=student_id:
  16. files.write(str(d)+'\n')
  17. else:
  18. flag=True
  19. if flag:
  20. print (f'学号为{student_id}的学生信息已删除!')
  21. else:
  22. print (f'没有找到id为{student_id}的学生信息')
  23. else:
  24. print('无学生记录')
  25. break
  26. show()
  27. choice = input ('是否继续?y/n:')
  28. if choice == 'y':
  29. continue
  30. else:
  31. break
  32. def show(): //显示文本中的数据
  33. student_lst=[]
  34. if os.path.exists(filename):
  35. with open(filename,'r',encoding='utf-8') as file:
  36. student=file.readlines()
  37. for item in student:
  38. student_lst.append(eval(item))
  39. if student_lst:
  40. show_student(student_lst)
  41. else:
  42. print('暂未保存学生数据!')

(2) Output interface

4. Modify student information

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.

(1) Function realization

  1. def modify():
  2. show()
  3. if os.path.exists(filename):
  4. with open(filename,'r',encoding='utf-8') as file:
  5. student_lst=file.readlines()
  6. else:
  7. return
  8. student_id=int(input('请输入学生id:'))
  9. with open(filename,'w',encoding='utf-8') as file1:
  10. for item in student_lst:
  11. d = dict (eval (item))
  12. if d ['id'] == student_id:
  13. print(f'已经找到id为{student_id}的学生')
  14. while True:
  15. try:
  16. d ['name'] = input ('请输入学生姓名:')
  17. d ['C语言'] = int (input ('请输入C语言成绩:'))
  18. d ['Python'] = int (input ('请输入Python的成绩:'))
  19. d ['Java'] = int (input ('请输入Java的成绩:'))
  20. except:
  21. print('输入的信息有误,重新输入!!')
  22. else:
  23. break
  24. file1.write(str(d)+'\n')
  25. print('修改信息成功!!!!!!!')
  26. else:
  27. file1.write(str(d)+'\n')
  28. switch = input ('是否要修改信息?y/n:')
  29. if switch == 'y':
  30. modify()

(2) Output interface

 

5. Find student information

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".

(1) Function realization

  1. def search(): //定义查找学生信息函数
  2. search_qurry=[]
  3. while True:
  4. id=''
  5. name=''
  6. if os.path.exists(filename):
  7. choice = int (input ('Id查询请按1,名字查询请按2:'))
  8. if choice == 1:
  9. id=int(input('请输入学生id:'))
  10. elif choice==2:
  11. name=input('请输入学生姓名:')
  12. else:
  13. print('输入有误,重新输入!')
  14. search()
  15. with open(filename,'r',encoding='utf-8') as file:
  16. student_lst=file.readlines()
  17. for item in student_lst:
  18. d = dict (eval (item))
  19. if id!='':
  20. if d['id']==id:
  21. search_qurry.append(d)
  22. elif name!='':
  23. if d['name']==name:
  24. search_qurry.append(d)
  25. show_student(search_qurry)
  26. search_qurry.clear()
  27. a=input('是否继续查找?y/n:')
  28. if a=='y':
  29. continue
  30. else:
  31. break
  32. def show_student(lst): //显示学生成绩列表
  33. if len(lst)==0:
  34. print('列表中无此学生的信息')
  35. return
  36. student_title='{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}'
  37. print(student_title.format('ID','姓名','C语言成绩','Python成绩','Java成绩','绩点'))
  38. student_data='{:^6}\t{:^12}\t{:^8}\t{:^8}\t{:^8}\t{:^8}'
  39. for item in lst:
  40. 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)))
  41. print ('\n')

(2) Output interface

6. Sorting

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.

(1) Function realization

  1. def sort():
  2. show()
  3. if os.path.exists(filename):
  4. with open(filename,'r',encoding='utf-8')as file:
  5. student_lst=file.readlines()
  6. student_new=[]
  7. for item in student_lst:
  8. d=dict(eval(item))
  9. student_new.append(d)
  10. else:
  11. return
  12. switch=input('排序方式(0.升序,1.降序)')
  13. if switch=='0':
  14. switch_bool=False
  15. elif switch=='1':
  16. switch_bool=True
  17. else:
  18. print('输入错误!')
  19. sort()
  20. choice=input('请选择排序方式(1.C语言成绩,2.Python成绩,3.Java成绩,4.绩点)')
  21. if choice=='1':
  22. student_new.sort(key=lambda x:int(x['C语言']),reverse=switch_bool)
  23. elif choice=='2':
  24. student_new.sort (key=lambda x: int (x ['Python']), reverse=switch_bool)
  25. elif choice=='3':
  26. student_new.sort (key=lambda x: int (x ['Java']), reverse=switch_bool)
  27. elif choice=='4':
  28. student_new.sort (key=lambda x: round((int (x ['C语言'])+int (x ['Python'])+int (x ['Java'])),2), reverse=switch_bool)
  29. else:
  30. print('选择错误!重新输入')
  31. sort()
  32. show_student(student_new)

(2) Output interface

7. Count the total number of students

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.

(1) Function realization

  1. def total():
  2. if os.path.exists(filename):
  3. with open(filename,'r',encoding='utf-8') as file:
  4. students=file.readlines()
  5. if students:
  6. print('系统内有{}个学生'.format(len(students)))
  7. else:
  8. print('系统内无学生记录!')
  9. else:
  10. print('暂未保存学生信息!')

(2) Output interface

8. Display all student information

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)

(1) Function realization

  1. def show_student(lst):
  2. if len(lst)==0:
  3. print('列表中无此学生的信息')
  4. return
  5. student_title='{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}'
  6. print(student_title.format('ID','姓名','C语言成绩','Python成绩','Java成绩','绩点'))
  7. student_data='{:^6}\t{:^12}\t{:^8}\t{:^8}\t{:^8}\t{:^8}'
  8. for item in lst:
  9. 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)))
  10. print ('\n')

(2) Output interface

3. Project packaging 

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

Four. Summary

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!



Category of website: technical article > Blog

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.

5 0
collect article
collected

Comment content: (supports up to 255 characters)