学生信息管理系统 制作一个小型的学生学籍管理系统,要求制作一个菜单,实现数据的录入,数据的显示,数据查找,数据的删除,数据的保存,数据的统计,数据的修改,系统的退出。系统的设计要求用到Python语言程序设计,信息存储要求用到结构体来实现,同时每一个功能用到一个函数。用python编写代码
时间: 2024-03-08 21:47:44 浏览: 66
基于C#实现的一个简单易用的学生学籍管理系统源码+项目说明(带GUI界面).zip
5星 · 资源好评率100%
好的,下面是一个简单的学生信息管理系统的Python代码示例,包含菜单、数据录入、数据显示、数据查找、数据删除、数据保存、数据统计、数据修改、系统退出等功能。请注意,这只是一个示例代码,实际应用中可能需要根据具体需求进行修改和补充。
```
# 定义学生信息结构体
class Student:
def __init__(self, id, name, gender, hometown, birthday, math_score, english_score, computer_score):
self.id = id
self.name = name
self.gender = gender
self.hometown = hometown
self.birthday = birthday
self.math_score = math_score
self.english_score = english_score
self.computer_score = computer_score
# 初始化学生列表
students = []
# 添加学生信息
def add_student():
id = input("请输入学号:")
name = input("请输入姓名:")
gender = input("请输入性别:")
hometown = input("请输入籍贯:")
birthday = input("请输入生日:")
math_score = int(input("请输入数学成绩:"))
english_score = int(input("请输入英语成绩:"))
computer_score = int(input("请输入计算机成绩:"))
student = Student(id, name, gender, hometown, birthday, math_score, english_score, computer_score)
students.append(student)
print("学生信息添加成功!")
# 显示学生信息
def show_students():
for student in students:
print("学号:{},姓名:{},性别:{},籍贯:{},生日:{},数学成绩:{},英语成绩:{},计算机成绩:{}".format(student.id, student.name, student.gender, student.hometown, student.birthday, student.math_score, student.english_score, student.computer_score))
# 查找学生信息
def search_student():
id = input("请输入要查找的学生学号:")
for student in students:
if student.id == id:
print("找到了该学生信息:学号:{},姓名:{},性别:{},籍贯:{},生日:{},数学成绩:{},英语成绩:{},计算机成绩:{}".format(student.id, student.name, student.gender, student.hometown, student.birthday, student.math_score, student.english_score, student.computer_score))
return
print("没有找到该学生信息!")
# 删除学生信息
def delete_student():
id = input("请输入要删除的学生学号:")
for student in students:
if student.id == id:
students.remove(student)
print("学生信息删除成功!")
return
print("没有找到该学生信息!")
# 保存学生信息到文件
def save_students():
file = open("students.txt", "w")
for student in students:
file.write("{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n".format(student.id, student.name, student.gender, student.hometown, student.birthday, student.math_score, student.english_score, student.computer_score))
file.close()
print("学生信息保存成功!")
# 从文件中读取学生信息
def load_students():
file = open("students.txt", "r")
for line in file:
fields = line.split("\t")
student = Student(fields[0], fields[1], fields[2], fields[3], fields[4], int(fields[5]), int(fields[6]), int(fields[7]))
students.append(student)
file.close()
print("学生信息加载成功!")
# 统计学生成绩
def calc_scores():
math_sum = 0
english_sum = 0
computer_sum = 0
for student in students:
math_sum += student.math_score
english_sum += student.english_score
computer_sum += student.computer_score
total_sum = math_sum + english_sum + computer_sum
math_avg = math_sum / len(students)
english_avg = english_sum / len(students)
computer_avg = computer_sum / len(students)
total_avg = total_sum / len(students)
math_pass_rate = len([s for s in students if s.math_score >= 60]) / len(students)
english_pass_rate = len([s for s in students if s.english_score >= 60]) / len(students)
computer_pass_rate = len([s for s in students if s.computer_score >= 60]) / len(students)
print("数学总分:{},英语总分:{},计算机总分:{},总分:{}".format(math_sum, english_sum, computer_sum, total_sum))
print("数学平均分:{},英语平均分:{},计算机平均分:{},总平均分:{}".format(math_avg, english_avg, computer_avg, total_avg))
print("数学及格率:{},英语及格率:{},计算机及格率:{}".format(math_pass_rate, english_pass_rate, computer_pass_rate))
# 菜单
def menu():
print("=" * 30)
print("1. 添加学生信息")
print("2. 显示学生信息")
print("3. 查找学生信息")
print("4. 删除学生信息")
print("5. 保存学生信息")
print("6. 统计学生成绩")
print("7. 修改学生信息")
print("0. 退出系统")
print("=" * 30)
# 修改学生信息
def modify_student():
id = input("请输入要修改的学生学号:")
for student in students:
if student.id == id:
student.name = input("请输入修改后的姓名:")
student.gender = input("请输入修改后的性别:")
student.hometown = input("请输入修改后的籍贯:")
student.birthday = input("请输入修改后的生日:")
student.math_score = int(input("请输入修改后的数学成绩:"))
student.english_score = int(input("请输入修改后的英语成绩:"))
student.computer_score = int(input("请输入修改后的计算机成绩:"))
print("学生信息修改成功!")
return
print("没有找到该学生信息!")
# 主程序
if __name__ == "__main__":
load_students()
while True:
menu()
choice = input("请输入操作序号:")
if choice == "1":
add_student()
elif choice == "2":
show_students()
elif choice == "3":
search_student()
elif choice == "4":
delete_student()
elif choice == "5":
save_students()
elif choice == "6":
calc_scores()
elif choice == "7":
modify_student()
elif choice == "0":
break
else:
print("输入有误,请重新输入!")
print("欢迎下次再来!")
```
阅读全文