python代码实现高数线代考试成绩.xls包含了某年级159个同学的高等数学考试成绩,和某年级288个同学的线性代数考试成绩。使用xlrd库读取这两个成绩,并显示出来
时间: 2024-06-09 16:08:19 浏览: 9
以下是使用xlrd库读取高数线代考试成绩.xls文件中的高等数学和线性代数考试成绩,并将其显示出来的Python代码实现:
```python
import xlrd
# 打开Excel文件
workbook = xlrd.open_workbook('高数线代考试成绩.xls')
# 获取高等数学成绩表格
math_sheet = workbook.sheet_by_name('高数成绩')
# 获取线性代数成绩表格
linear_algebra_sheet = workbook.sheet_by_name('线代成绩')
# 获取高等数学成绩
math_scores = []
for i in range(1, math_sheet.nrows):
math_scores.append(math_sheet.cell_value(i, 1))
# 获取线性代数成绩
linear_algebra_scores = []
for i in range(1, linear_algebra_sheet.nrows):
linear_algebra_scores.append(linear_algebra_sheet.cell_value(i, 1))
# 显示高等数学成绩
print('高等数学成绩:')
for i, score in enumerate(math_scores):
print('学生{}的成绩为:{}'.format(i+1, score))
# 显示线性代数成绩
print('线性代数成绩:')
for i, score in enumerate(linear_algebra_scores):
print('学生{}的成绩为:{}'.format(i+1, score))
```
运行上述代码,即可输出高等数学和线性代数考试成绩。注意,需要将代码中的文件路径修改为实际文件的路径。
相关推荐
![ppt](https://img-home.csdnimg.cn/images/20210720083527.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)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)