用Python写一个成绩管理系统
时间: 2024-03-06 22:42:52 浏览: 22
以下是一个简单的Python成绩管理系统的例子,可以根据需要进行修改和扩展:
```python
class Student:
def __init__(self, name, score):
self.name = name
self.score = score
class ScoreSystem:
def __init__(self):
self.students = []
def add_student(self, name, score):
student = Student(name, score)
self.students.append(student)
def remove_student(self, name):
for student in self.students:
if student.name == name:
self.students.remove(student)
return True
return False
def update_score(self, name, score):
for student in self.students:
if student.name == name:
student.score = score
return True
return False
def get_score(self, name):
for student in self.students:
if student.name == name:
return student.score
return None
def get_average_score(self):
if len(self.students) == 0:
return None
total_score = 0
for student in self.students:
total_score += student.score
return total_score / len(self.students)
score_system = ScoreSystem()
score_system.add_student('Alice', 80)
score_system.add_student('Bob', 90)
score_system.add_student('Charlie', 70)
print('Average score:', score_system.get_average_score())
print('Score of Alice:', score_system.get_score('Alice'))
score_system.update_score('Bob', 95)
score_system.remove_student('Charlie')
print('Average score:', score_system.get_average_score())
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)