本文实例为大家分享了python实现学生信息管理系统的具体代码,供大家参考,具体内容如下
代码如下:
Project.py文件内容:
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
|
class Student( object ): # 建立学生信息储存的列表(嵌套的方式) studentInformation = [] # 对学生对象的数据进行说明 studentShow = [ "学号:" , "姓名:" , "年龄:" ] # 录入学生 def addstudent( self ): sno = input ( "请输入学号:" ) name = input ( "请输入姓名:" ) sage = input ( "请输入年龄:" ) # 建立一个列表,用于暂时存储 student = [sno, name, sage] # 加入学生(判断学号是否重复) x = 0 # 刚开始录入学生时,学号不可能重复 if len ( self .studentInformation) = = 0 : self .studentInformation.append(student) # 判断重复 else : while x < len ( self .studentInformation): if self .studentInformation[x][ 0 ] ! = sno: x + = 1 else : print ( "学号重复!!!\n请重新输入序号!!!" ) break else : self .studentInformation.append(student) print ( "加入成功!!!" ) # 输出学生 def showstudent( self ): print ( "学生信息输出如下:" ) for i in range ( len ( self .studentInformation)): print ( self .studentShow[ 0 ] + self .studentInformation[i][ 0 ], end = " " ) print ( self .studentShow[ 1 ] + self .studentInformation[i][ 1 ], end = " " ) print ( self .studentShow[ 2 ] + self .studentInformation[i][ 2 ]) # 删除学生 def deletestudent( self ): x = 0 sno = input ( "请输入学生学号:" ) while x < len ( self .studentInformation): if self .studentInformation[x][ 0 ] = = sno: del self .studentInformation[x] print ( "删除学生成功!!!" ) break else : x + = 1 else : print ( "不存在当前学生!!!" ) # 查询学生 def selectstudent( self ): x = 0 sno = input ( "请输入查询学生的学号" ) while x < len ( self .studentInformation): if self .studentInformation[x][ 0 ] = = sno: print ( self .studentShow[ 0 ] + self .studentInformation[x][ 0 ], end = " " ) print ( self .studentShow[ 1 ] + self .studentInformation[x][ 1 ], end = " " ) print ( self .studentShow[ 2 ] + self .studentInformation[x][ 2 ]) break else : x + = 1 else : print ( "未查询到当前学生!!!" ) # 修改学生 def changestudent( self ): x = 0 sno = input ( "请输入修改学生的学号:" ) while x < len ( self .studentInformation): if self .studentInformation[x][ 0 ] = = sno: name = input ( "请输入修改后的姓名:" ) sage = input ( "请输入修改后的年龄:" ) self .studentInformation[x][ 1 ] = name self .studentInformation[x][ 2 ] = sage print ( "修改成功!!!" ) break else : x + = 1 # 界面打印 @staticmethod def printui(): print ( "输入:0 --退出程序--" ) print ( "输入:1 --录入学生--" ) print ( "输入:2 --输出学生--" ) print ( "输入:3 --删除学生--" ) print ( "输入:4 --查询学生--" ) print ( "输入:5 --修改学生--" ) # 程序调用 def run( self ): self .printui() number = input ( "请输入功能前面的代码:" ) # 无限循环 var = 1 while var = = 1 : if int (number) = = 1 : self .addstudent() self .printui() number = input ( "请输入功能前面的代码:" ) elif int (number) = = 2 : self .showstudent() self .printui() number = input ( "请输入功能前面的代码:" ) elif int (number) = = 3 : self .deletestudent() self .printui() number = input ( "请输入功能前面的代码:" ) elif int (number) = = 4 : self .selectstudent() self .printui() number = input ( "请输入功能前面的代码:" ) elif int (number) = = 5 : self .changestudent() self .printui() number = input ( "请输入功能前面的代码:" ) elif int (number) = = 0 : break else : print ( "您输入的序号不对!\n请重新输入!" ) self .printui() number = input ( "请输入功能前面的代码:" ) else : print ( "再见!" ) exit() |
text.py文件:
1
2
3
4
|
from Project import Student # 实例化对象 stu = Student() stu.run() |
运行结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_52889967/article/details/113886306