Questions
Questions

Fal25_CS003C_74229 Ch. 5 Pre-Quiz (Remotely Proctored)

Single choice

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)

Options
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
View Explanation

View Explanation

Verified Answer
Please login to view
Step-by-Step Analysis
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

Log in for full answers

We've collected over 50,000 authentic exam questions and detailed explanations from around the globe. Log in now and get instant access to the answers!

More Practical Tools for Students Powered by AI Study Helper

Join us and instantly unlock extensive past papers & exclusive solutions to get a head start on your studies!