Python起步之學生資訊管理系統
阿新 • • 發佈:2019-01-24
#編譯環境為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('輸入有誤,檢查後重新輸入!')