因為最近打算開發一個信息管理系統,有點復雜。
作為初學者的我不是很懂。所以從簡單的開始,先練練手。
一步一步來,踏踏實實的走。千里之行始于足下。
所以參考網上的一篇技術文章,稍微修改了一下,做了這個系統。
文章鏈接:https://blog.csdn.net/xiao_huo_ban/article/details/79808778
(本來想弄轉載的,但是要原文作者允許太麻煩了)
代碼:student_information.py
#!/usr/bin/python
# -*- coding: UTF-8 -*-
students = []
def showStart():
print('-' * 40)
print('=' * 10 + '學生管理系統 v1.0' + '=' * 10)
print('1.添加學生的信息')
print('2.刪除學生的信息')
print('3.修改學生的信息')
print('4.查詢學生的信息')
print('5.展示所有學生信息')
print('6.退出系統')
print('-' * 40)
def addStudent():
name = input('請輸入姓名:')
studentId = input('請輸入學號:')
age = input('請輸入年齡:')
studentInformation = {}
studentInformation['name'] = name
studentInformation['id'] = studentId
studentInformation['age'] = age
return studentInformation
def modification(students):
modificationNum = input('請輸入要修改學生的id:')
x = -1
for num in students:
x += 1
if modificationNum == num['id']:
students[x] = addStudent()
def selectStudent(students):
selectNum = input('請輸入要查詢學生的id:')
judge = 1
for student in students:
if selectNum == student['id']:
print('下面顯示該學生的信息...')
print('id 姓名 年齡')
print('%s %s %s' % (student['id'], student['name'], student['age']))
judge = 0
break
if judge == 1:
print('沒有該學生...')
def classroom():
print('*' * 30)
print('下面顯示班級所有學生信息...')
print('id 姓名 年齡')
for student in students:
print('%s %s %s' % (student['id'], student['name'], student['age']))
def deleteStudentInformation(students):
deleteNum = int(input('請輸入要刪除的序號(0是第一個):'))
del students[deleteNum]
print('該學生信息已刪除!')
def main():
while True:
showStart()
key = int(input('請選擇功能(序號):'))
if key == 1:
students.append(addStudent())
elif key == 2:
deleteStudentInformation(students)
elif key == 3:
modification(students)
elif key == 4:
selectStudent(students)
elif key == 5:
classroom()
elif key == 6:
quitconfirm = input('您真的要退出嗎?(輸入yes或者no):')
if quitconfirm == 'yes':
break
else:
print('輸入有誤,請重新輸入!')
if __name__ == '__main__':
main()
無錯誤,可放心拷貝!
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
