完成一个学生成绩管理系统,学生资料包括:姓名、性别、英语成绩、数学成绩、C语言成绩 总分、平均分。具备容错性。能够完成以下内容: (1)输入学生资料 (2)查询学生资料
时间: 2023-12-25 16:05:34 浏览: 47
好的,我可以帮你完成学生成绩管理系统,包括输入学生资料和查询学生资料的功能。以下是一个示例代码:
```python
class Student:
def __init__(self, name, gender, english_score, math_score, c_score):
self.name = name
self.gender = gender
self.english_score = english_score
self.math_score = math_score
self.c_score = c_score
self.total_score = english_score + math_score + c_score
self.average_score = self.total_score / 3
students = []
def add_student():
name = input("请输入学生姓名: ")
gender = input("请输入学生性别: ")
english_score = float(input("请输入英语成绩: "))
math_score = float(input("请输入数学成绩: "))
c_score = float(input("请输入C语言成绩: "))
student = Student(name, gender, english_score, math_score, c_score)
students.append(student)
print("学生资料添加成功!")
def search_student():
name = input("请输入要查询的学生姓名: ")
found = False
for student in students:
if student.name == name:
found = True
print("姓名:", student.name)
print("性别:", student.gender)
print("英语成绩:", student.english_score)
print("数学成绩:", student.math_score)
print("C语言成绩:", student.c_score)
print("总分:", student.total_score)
print("平均分:", student.average_score)
print()
if not found:
print("未找到该学生!")
while True:
print("请选择操作:")
print("1. 输入学生资料")
print("2. 查询学生资料")
print("3. 退出系统")
choice = input("请输入选项数字: ")
if choice == "1":
add_student()
elif choice == "2":
search_student()
elif choice == "3":
print("感谢使用学生成绩管理系统!")
break
else:
print("无效的选项,请重新输入!")
```
这段代码会提示用户选择操作,然后根据用户的选择执行相应的功能。你可以根据自己的需求进行修改和扩展。
阅读全文