当前位置: 首页 >资讯 > 互联科技百科 > 内容

📚 Python选修课作业的某一小题 🌟

互联科技百科
导读 假定下面字典是同一个专业选修不同课程的学生信息:```pythonstudents = {"Alice": {"course": "Data Science", "score": 85},"Bob"...

假定下面字典是同一个专业选修不同课程的学生信息:

```python

students = {

"Alice": {"course": "Data Science", "score": 85},

"Bob": {"course": "Web Development", "score": 90},

"Charlie": {"course": "AI", "score": 78},

"Diana": {"course": "Cybersecurity", "score": 88}

}

```

通过这段代码,我们可以轻松分析每个学生的学习情况。🔍

首先,让我们计算所有学生的平均分数:

```python

total_score = sum(student['score'] for student in students.values())

average_score = total_score / len(students)

print(f"全班平均分:{average_score:.2f}")

```

接着,找出最高分的学生:

```python

top_student = max(students, key=lambda x: students[x]['score'])

print(f"最高分学生:{top_student} ({students[top_student]['score']}分)")

```

通过这些简单的操作,我们不仅完成了任务,还学习了如何处理字典和列表推导式。💡

希望每位同学都能在Python的世界里找到乐趣!🎉

免责声明:本文由用户上传,如有侵权请联系删除!