题目
题目

Fal25_CS003C_74229 Ch. 5 Pre-Quiz (Remotely Proctored)

单项选择题

Given the following code snippet, which statement correctly allows the function to update the global variable total?1. total = 02. def main() :3. avg = 04. for i in range(6) :5. iSquared = i * i6. total = total + iSquared7. avg = total / i8. print(total)9. print(avg)

查看解析

查看解析

标准答案
Please login to view
思路分析
The given code snippet appears to intend updating a global variable named total from within a function. In Python, to modify a global variable inside a function, you must declare it as global inside that function before you assign to it. Option analysis: - If you place a statement global total inside the function, you tell Python that total refers to the module-level variable rather than a local one. This allows total = total + iSquared to read the current global total and write the upda......Login to view full explanation

登录即可查看完整答案

我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!