代码标注笔试题.docxVIP

  • 0
  • 0
  • 约7.93千字
  • 约 12页
  • 2026-08-12 发布于贵州
  • 举报

代码标注笔试题

考试时间:______分钟总分:______分姓名:______

第一题

阅读以下Python代码片段,请按照要求进行标注。

```python

defcalculate_score(grades):

total=0

count=0

forgradeingrades:

ifgrade0:

continue#忽略无效成绩

total+=grade

count+=1

average=total/countifcount!=0else0

returnaverage

#示例调用

student_grades=[85,92,78,65,-1,0]

result=calculate_score(student_grades)

print(平均分:,result)

```

1.请在函数`calculate_score`的定义行上方标注`def`关键字。

2.请在变量`total`的声明行和`count`的声明行上方分别标注它们的数据类型(假设为整数)。

3.请在`for`循环的`for`关键字下方标注循环变量`grade`。

4.

文档评论(0)

1亿VIP精品文档

相关文档