题目
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 = 0 2. def main() : 3. avg = 0 4. for i in range(6) : 5. iSquared = i * i 6. total = total + iSquared 7. avg = total / i 8. print(total) 9. print(avg)
选项
A.move line 1 inside the function definition
B.line 1 already allows the total variable to be updated
C.add the keyword global to line 1
D.add the statement global total after line 2
查看解析
标准答案
Please login to view
思路分析
The question asks which modification enables the function to update the global variable total while executing the given code snippet.
Option 1: 'move line 1 inside the function definition' would place total = 0 inside the function. However, without declaring total as global inside the function, Python will treat total as a local variable ......Login to view full explanation登录即可查看完整答案
我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。
类似问题
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)
A global variable is available everywhere in the code.
Which of the following statements is not true regarding global variables?
In a consumer society, many adults channel creativity into buying things
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!