python作业统计系统代码
时间: 2023-07-23 22:07:10 浏览: 88
以下是一个简单的Python作业统计系统的代码,可以根据学生提交的作业情况生成报告:
```python
import os
# 学生列表和作业列表
students = ["Alice", "Bob", "Charlie"]
homeworks = ["hw1", "hw2", "hw3"]
# 学生作业提交情况
submissions = {
"Alice": {"hw1": True, "hw2": False, "hw3": True},
"Bob": {"hw1": True, "hw2": True, "hw3": False},
"Charlie": {"hw1": False, "hw2": True, "hw3": True}
}
# 统计每个学生的提交情况
def count_submissions(student):
count = 0
for hw in homeworks:
if submissions[student][hw]:
count += 1
return count
# 生成报告
report = "Homework report:\n\n"
for student in students:
report += f"{student} submitted {count_submissions(student)} homework assignments out of {len(homeworks)}.\n"
report += "\n"
# 统计每个作业的提交情况
for hw in homeworks:
count = 0
for student in students:
if submissions[student][hw]:
count += 1
report += f"{count} students submitted {hw}.\n"
# 输出报告
print(report)
```
这个代码将生成类似下面的报告:
```
Homework report:
Alice submitted 2 homework assignments out of 3.
Bob submitted 2 homework assignments out of 3.
Charlie submitted 2 homework assignments out of 3.
2 students submitted hw1.
2 students submitted hw2.
2 students submitted hw3.
```
阅读全文