用python编程成绩管理系统
时间: 2023-10-18 07:04:45 浏览: 42
很抱歉,我是一个语言模型AI,没有图形界面,无法为您提供编写成绩管理系统的可视化界面,但以下是一个简单的成绩管理系统的代码示例,可以通过命令行进行操作:
```python
def add_student(students, name, scores):
students[name] = scores
def remove_student(students, name):
del students[name]
def display_student(students, name):
print(name + ": " + str(students[name]))
def display_all(students):
for name, scores in students.items():
display_student(students, name)
def calculate_average(scores):
return sum(scores) / len(scores)
def display_average(students, name):
scores = students[name]
average = calculate_average(scores)
print(name + "'s average score is " + str(average))
students = {}
while True:
print("Enter 1 to add a student")
print("Enter 2 to remove a student")
print("Enter 3 to display a student's scores")
print("Enter 4 to display all students' scores")
print("Enter 5 to display a student's average score")
print("Enter 6 to exit")
choice = input("Enter your choice: ")
if choice == "1":
name = input("Enter student name: ")
scores = input("Enter student's scores separated by commas: ")
scores = [int(score) for score in scores.split(",")]
add_student(students, name, scores)
elif choice == "2":
name = input("Enter student name: ")
remove_student(students, name)
elif choice == "3":
name = input("Enter student name: ")
display_student(students, name)
elif choice == "4":
display_all(students)
elif choice == "5":
name = input("Enter student name: ")
display_average(students, name)
elif choice == "6":
break
else:
print("Invalid choice. Please try again.")
```
在这个简单的成绩管理系统中,我们定义了一些函数来执行不同的操作,如添加学生、删除学生、显示单个学生的分数、显示所有学生的分数以及计算并显示单个学生的平均分数。
在主循环中,我们打印出一些选项供用户选择,然后根据用户的选择执行相应的操作。这个程序没有保存学生信息,当程序结束时,所有数据都会丢失。
如果您想要一个更完整的成绩管理系统,您可以考虑使用数据库或文件来保存数据。您还可以添加更多的功能,如修改学生分数、搜索学生、根据分数排序学生等等。