本文实例为大家分享了python学生管理系统的具体代码,供大家参考,具体内容如下
基于列表存储的学生管理系统,实现如下功能
==================
学生管理系统
1、添加学生信息
2、删除学生信息
3、查询学生信息
4、修改学生信息
5、显示所有学生信息
6、退出
==================
代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
import re student = [] def appendStudentInfo(): studentinfo = { "Name" :" "," ID ":" "," 语文 ":" "," 数学 ":" "," 英语 ":" "," 总分 ":" "} studentinfo[ "Name" ] = input ( "请输入学生姓名:" ) idflag = True while idflag: studentinfo[ "ID" ] = input ( "请输入学生学号:" ) pattern = re. compile ( "^\d{3}$" ) if not re.match(pattern,studentinfo[ "ID" ]) : print ( "输入错误,请重新输入" ) idflag = True if querystudent(studentinfo[ "ID" ]) = = True : print ( "该学号已经存在请重新输入" ) idflag = True if querystudent(studentinfo[ "ID" ]) = = False and re.match(pattern,studentinfo[ "ID" ]): idflag = False studentinfo[ "语文" ] = input ( "请输入语文成绩:" ) while not studentinfo[ "语文" ].isdigit() or int (studentinfo[ "语文" ])> 100 or int (studentinfo[ "语文" ])< 0 : studentinfo[ "语文" ] = input ( "输入错误,请重新输入:" ) studentinfo[ "数学" ] = input ( "请输入数学成绩:" ) while not studentinfo[ "数学" ].isdigit() or int (studentinfo[ "数学" ]) > 100 or int (studentinfo[ "数学" ]) < 0 : studentinfo[ "数学" ] = input ( "输入错误,请重新输入:" ) studentinfo[ "英语" ] = input ( "请输入英语成绩:" ) while not studentinfo[ "英语" ].isdigit() or int (studentinfo[ "英语" ]) > 100 or int (studentinfo[ "英语" ]) < 0 : studentinfo[ "英语" ] = input ( "输入错误,请重新输入:" ) studentinfo[ "总分" ] = int (studentinfo[ "语文" ]) + int (studentinfo[ "英语" ]) + int (studentinfo[ "数学" ]) student.append(studentinfo) def delstudent(): delstudentid = input ( "请输入要删除的学生学号:" ) flag = False for item in student: if item[ "ID" ] = = delstudentid: flag = True print ( "要删除学生的相关信息如下:" ) print (item) select = input ( "是否删除:是(Y)/否(N)" ) if select = = "Y" or select = = "y" : student.remove(item) print ( "删除成功" ) elif select = = "N" or select = = "n" : print ( "取消删除" ) else : print ( "输入错误" ) if flag = = False : print ( "未搜索到该学生" ) def querystudent(querystudentid): flag = False for item in student: if item[ "ID" ] = = querystudentid: flag = True return flag def modifystudentifo(): delstudentid = input ( "请输入要修改的学生学号:" ) flag = False for item in student: if item[ "ID" ] = = delstudentid: print ( "查询内容如下:" ) print (item) flag = True while True : modifymenu = input ( "请输入修改选项:1、姓名,2、语文成绩,3、数学成绩,4、英语成绩,5、退出" ) while not modifymenu.isdigit(): modifymenu = input ( "输入错误,请重新输入:" ) if int (modifymenu) = = 1 : item[ "Name" ] = input ( "请重新输入学生姓名:" ) elif int (modifymenu) = = 2 : item[ "语文" ] = input ( "请重新输入学生语文成绩:" ) elif int (modifymenu) = = 3 : item[ "数学" ] = input ( "请重新输入学生数学成绩:" ) elif int (modifymenu) = = 4 : item[ "英语" ] = input ( "请重新输入学生英语成绩:" ) elif int (modifymenu) = = 5 : break else : print ( "输入序号无效" ) item[ "总分" ] = int (item[ "语文" ]) + int (item[ "英语" ]) + int (item[ "数学" ]) print ( "修改结果如下:" ) print (item) if flag = = False : print ( "未搜索到该学生" ) def allinfo(): for item in student: print (item) def iteminfo(querystudentid): for item in student: if item[ "ID" ] = = querystudentid: print ( "查询内容如下:" ) print (item) def studentMenu(): print ( "=" * 30 ) print ( "学生管理系统" ) print ( "1、添加学生信息" ) print ( "2、删除学生信息" ) print ( "3、查询学生信息" ) print ( "4、修改学生信息" ) print ( "5、显示所有学生信息" ) print ( "6、退出" ) print ( "=" * 30 ) if __name__ = = '__main__' : while True : studentMenu() menuindex = input ( "请输入选项序号:" ) while not menuindex.isdigit(): menuindex = input ( "输入错误,请重新输入:" ) if int (menuindex) = = 1 : appendStudentInfo() elif int (menuindex) = = 2 : delstudent() elif int (menuindex) = = 3 : querystudentid = input ( "请输入要查询的学生学号:" ) if querystudent(querystudentid) = = True : iteminfo(querystudentid) else : print ( "未搜索到该学生" ) elif int (menuindex) = = 4 : modifystudentifo() elif int (menuindex) = = 5 : allinfo() elif int (menuindex) = = 6 : break else : print ( "输入序号无效" ) |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/yaoliuwei1426/article/details/80690927