学生管理系统(基础版)
- 将学生管理系统各个功能都封装成函数,在判断指令时方便调用。
def welcome():
print('''
-----------------------------------------------------------
| 欢迎进入学生管理系统 |
| |
| 1.学生信息录入 2.学生成绩查询 3.查找学生信息 |
| 4.录入学生成绩 5.课程平均值 6.所有学生信息 |
| 7.退出系统 |
-----------------------------------------------------------
''')
return input("请输入您要操作的选项:")
def saveStu(studict):
stuId = input("请输入您的学号:")
if stuId in studict:
print("此学号已存在,请咨询老师...")
return
name = input("请输入您的姓名:")
sex = input("请输入您的性别:")
score = 0
phon = input("请输入你的电话:")
student = {"name": name, "sex": sex, "score": score, "phon": phon}
studict[stuId] = student
def searchScore(studict):
stuId = input("请输入你的学号:")
if stuId in studict:
stu = studict.get(stuId)
print("你的成绩:%d" % stu["score"])
else:
print("你输入的学号不存在")
def searchStu(studict):
stuId = input("请输入你的学号:")
if stuId in studict:
stu = studict.get(stuId)
print("学号:%s,姓名:%s,性别:%s,成绩:%d,电话:%s" % (stuId, stu["name"], stu["sex"], stu["score"], stu["phon"]))
else:
print("你输入的学号不存在")
def stuScore(studict):
stuId = input("请输入你的学号:")
if stuId in studict:
score = int(input("请输入你的成绩:"))
studict[stuId]["score"] = score
else:
print("你输入的学号不存在")
def averScore(studict):
scoreList = []
sum = 0
for stuId in studict:
scoreList.append(studict.get(stuId)["score"])
for i in scoreList:
sum += i
averS = sum / len(scoreList)
print(averS)
def searchAllStu(studict):
for stuId in studict:
stu = studict.get(stuId)
print("学号:%s,姓名:%s,性别:%s,成绩:%d,电话:%s" % (stuId, stu["name"], stu["sex"], stu["score"], stu["phon"]))
studict = {}
while True:
num = welcome()
if num == "1":
print("学生信息录入")
saveStu(studict)
elif num == "2":
print("学生成绩查询")
searchScore(studict)
elif num == "3":
print("查找学生信息")
searchStu(studict)
elif num == "4":
print("录入学生成绩")
stuScore(studict)
elif num == "5":
print("成绩平均值")
averScore(studict)
elif num == "6":
print("所有学生信息")
searchAllStu(studict)
elif num == "7":
print("退出系统")
break
else:
print("输入有误,请重新输入")