PCEP • Practice Test 30
Free PCEP practice test — 15 questions with explanations. Set 30. No signup required.
A data scientist needs to read a list of floats from a file, one per line, and compute the sum. The current code:
total = 0.0
with open("data.txt") as f:
for line in f:total = total + line
print(total)When run, a TypeError occurs: unsupported operand type(s) for +: 'float' and 'str'. The scientist knows that line is a string. Which fix will correctly sum the numbers?