python简易成绩管理系统
时间: 2023-11-30 10:43:18 浏览: 79
以下是一个简单的Python成绩管理系统的实现,使用单链表来存储学生信息和成绩:
```python
class Node:
def __init__(self, name, score, next=None):
self.name = name
self.score = score
self.next = next
class ScoreList:
def __init__(self):
self.head = None
def add(self, name, score):
node = Node(name, score)
if self.head is None:
self.head = node
else:
current = self.head
while current.next is not None:
current = current.next
current.next = node
def remove(self, name):
if self.head is None:
return
if self.head.name == name:
self.head = self.head.next
return
current = self.head
while current.next is not None:
if current.next.name == name:
current.next = current.next.next
return
current = current.next
def find(self, name):
current = self.head
while current is not None:
if current.name == name:
return current.score
current = current.next
return None
def print_all(self):
current = self.head
while current is not None:
print(current.name, current.score)
current = current.next
```
这个成绩管理系统包含了四个方法:add()用于添加学生信息和成绩,remove()用于删除学生信息和成绩,find()用于查找学生的成绩,print_all()用于打印所有学生的信息和成绩。
阅读全文