本文實例為大家分享了python學生信息管理系統的具體代碼,供大家參考,具體內容如下
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
|
#編譯環境為python3 #學生信息管理系統包括基本的信息功能,能夠實現學生信息的輸入,查詢,增添和刪除 #基本框架:開始操作菜單,接收輸入選項,調用相應的函數實現對應的功能,循環回到開始菜單, #操作菜單: student = [] def studentMeau(): print ( '-' * 30 ) print ( '-------學生信息管理系統-------' ) print ( ' 1、添加學生信息' ) print ( ' 2、刪除學生信息' ) print ( ' 3、查詢學生信息' ) print ( ' 4、修改學生信息' ) print ( ' 5、退出' ) print ( '-' * 30 ) def appendStuInf(): studentInf = { 'Name' :' ',' Id ':' ',' Sex ':' ',' Age ':' ',' Project ':' '} studentInf[ 'Name' ] = input ( '請輸入學生姓名:' ) studentInf[ 'Id' ] = input ( '請輸入學生學號:' ) studentInf[ 'Sex' ] = input ( '請輸入學生性別:' ) studentInf[ 'Age' ] = input ( '請輸入學生年齡:' ) studentInf[ 'Project' ] = input ( '請輸入學生專業:' ) student.append(studentInf) #print(student) def deleteStuInf(): num = input ( '請輸入要刪除學生的學號:' ) # for i in range(len(student)): # if student[i]['Id'] == num: # student.remove(student[i]) # break for stu_inf in student: if stu_inf[ 'Id' ] = = num: student.remove(stu_inf) break # print(student) def inquireStuInf(): flag = False num = input ( '請輸入要查詢學生的學號:' ) for stu_inf in student: if stu_inf[ 'Id' ] = = num: print ( 'name: ' + stu_inf[ 'Name' ] + '\n' ) print ( 'Id: ' + stu_inf[ 'Id' ] + '\n' ) print ( 'Sex: ' + stu_inf[ 'Sex' ] + '\n' ) print ( 'Age: ' + stu_inf[ 'Age' ] + '\n' ) print ( 'Project: ' + stu_inf[ 'Project' ] + '\n' ) flag = True break if flag = = False : print ( '沒有查詢到該生的信息!' ) def modifyStuInf(): num = input ( '請輸入要修改學生的學號:' ) flag = False for stu_inf in student: if stu_inf[ 'Id' ] = = num: print ( 'name: ' + stu_inf[ 'Name' ] + '\n' ) print ( 'Id: ' + stu_inf[ 'Id' ] + '\n' ) print ( 'Sex: ' + stu_inf[ 'Sex' ] + '\n' ) print ( 'Age: ' + stu_inf[ 'Age' ] + '\n' ) print ( 'Project: ' + stu_inf[ 'Project' ] + '\n' ) flag = True break if flag = = False : print ( '沒有該生的信息!' ) return print ( '1:姓名 ---- 2:學號 ---- 3:性別 ---- 4:年齡 ---- 5:專業 ---- 6:退出' + '\n' ) while True : choice = int ( input ( "請輸入選項序號:" )) if choice = = 1 : stu_inf[ 'Name' ] = input ( '請重新輸入姓名:' ) print ( '姓名已更正為:' + stu_inf[ 'Name' ] + '\n' ) elif choice = = 2 : stu_inf[ 'Id' ] = input ( '請重新輸入學號:' ) print ( '學號已更正為:' + stu_inf[ 'Id' ] + '\n' ) elif choice = = 3 : stu_inf[ 'Sex' ] = input ( '請重新輸入性別:' ) print ( '性別已更正為:' + stu_inf[ 'Sex' ] + '\n' ) elif choice = = 4 : stu_inf[ 'Age' ] = input ( '請重新輸入年齡:' ) print ( '年齡已更正為:' + stu_inf[ 'Age' ] + '\n' ) elif choice = = 5 : stu_inf[ 'Project' ] = input ( '請重新輸入專業:' ) print ( '專業已更正為:' + stu_inf[ 'Project' ] + '\n' ) elif choice = = 6 : print ( '修改完畢!' ) break else : print ( '輸入有誤,不予執行!' ) while True : studentMeau() choice = int ( input ( "請輸入選項序號:" )) if choice = = 1 : #添加學生信息 appendStuInf() elif choice = = 2 : #刪除學生信息 deleteStuInf() elif choice = = 3 : #查詢學生信息 inquireStuInf() elif choice = = 4 : #修改學生信息 modifyStuInf() elif choice = = 5 : print ( '謝謝使用!' ) break else : print ( '輸入有誤,檢查后重新輸入!' ) |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://blog.csdn.net/m0_37338590/article/details/78010630