Question: python; In the code below, we compute the sum of integers in a file by reading them one line at a time. Rearrange the following
python; In the code below, we compute the sum of integers in a file by reading them one line at a time.
Rearrange the following lines of code so that the input file is closed even if the int function raises an exception. Follow Programming Tip Do not use except and finally in the same try statement" in the Exception Handling section by placing the tryblock and finally clause inside the outer try block.
: Rearrange the code so that the input file is closed even if the int function raises an exception.
qxzqy
In the code below, we compute the sum of integers in a file by reading them one line at a time.
Rearrange the following lines of code so that the input file is closed even if the int function raises an exception. Follow Programming Tip Do not use except and finally in the same try statement" in the Exception Handling section by placing the try block and finally clause inside the outer try block.
How to use this tool
Unused
try :
total total value
printTotal: total
printClosing file"
infile.close
infile openinput
total
value intline
finally :
for line in infile :
Tester.py
except ValueError :
printError: Not an integer value."
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
