使用python完成超級基礎的學生管理系統,供大家參考,具體內容如下
說明:
1、本學生管理系統非常非常簡易,只有增,顯,查,刪,改功能,對于Python新手容易看懂上手。
2、信息的存儲只使用了字典和列表。
3、不喜勿噴。
代碼:
1、主循環框架
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
|
while True : print (info_str) action = input ( "請輸入想要進行的操作:" ) if action = = '0' : print ( "再見。" ) break elif action = = '1' : print ( "新建學生信息" ) elif action = = '2' : print ( "顯示全部學生" ) elif action = = '3' : print ( "查詢學生信息" ) elif action = = '4' : print ( "刪除學生信息" ) elif action = = '5' : print ( "修改學生信息" ) else : print ( "你的輸入有錯誤,請重新輸入。" ) |
2、源代碼
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
|
info_str = """ ************************* 1.新建學生信息 2.顯示全部學生 3.查詢學生信息 4.刪除學生信息 5.修改學生信息 0.退出系統 ************************* """ """姓名、語文成績、數學成績、英語成績、總分""" students = [ { 'Name' : '張大炮' , 'Chinese' : '95' , 'Math' : '65' , 'English' : '65' , 'Score' : '215' }, { 'Name' : '張益達' , 'Chinese' : '65' , 'Math' : '95' , 'English' : '65' , 'Score' : '215' }, { 'Name' : 'Snack' , 'Chinese' : '65' , 'Math' : '65' , 'English' : '95' , 'Score' : '215' }, ] while True : """"程序主循環""" print (info_str) action = input ( "請輸入想要進行的操作:" ) if action = = '0' : """結束條件""" print ( "撒由那拉。" ) break elif action = = '1' : print ( "新建學生信息" ) Name = input ( "請輸入名字:" ) Chinese = input ( "請輸入語文成績:" ) Math = input ( "請輸入數學成績:" ) English = input ( "請輸入英語成績:" ) Score = int (Chinese) + int (Math) + int (English) student = { 'Name' :Name, 'Chinese' :Chinese, 'Math' :Math, 'English' :English, 'Score' :Score } students.append(student) elif action = = '2' : print ( "顯示全部學生" ) for student in students: print (student) elif action = = '3' : print ( "查詢學生信息" ) Name = input ( '請輸入需要查詢的名字:' ) for student in students: if student[ 'Name' ] = = Name: print (student) else : print ( "{}信息不存在" . format (Name)) elif action = = '4' : print ( "刪除學生信息" ) Name = input ( "請輸入需要刪除的名字:" ) for student in students: if student[ 'Name' ] = = Name: students.remove(student) break else : print ( "{}信息不存在" . format (Name)) elif action = = '5' : print ( "修改學生信息" ) Name = input ( "請輸入需要修改的名字:" ) for student in students: if student[ 'Name' ] = = Name: student[ 'Name' ] = input ( "請輸入名字:" ) student[ 'Chinese' ] = input ( "請輸入語文成績:" ) student[ 'Math' ] = input ( "請輸入數學成績:" ) student[ 'English' ] = input ( "請輸入英語成績:" ) student[ 'Score' ] = int (student[ 'Chinese' ]) + int (student[ 'Math' ]) + int (student[ 'English' ]) else : print ( "{}信息不存在" . format (Name)) else : print ( "你的輸入有錯誤,請重新輸入。" ) |
總結
1、代碼框架簡潔明了,添加功能只需要在主循環中增加即可。
2、超級基礎,不喜勿噴。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/flower10_/article/details/106954056