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.
7.26.1: Rearrange the code so that the input file is closed even if the int function raises an exception.
579624.4455300.qx3zqy7
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
print("Total:", total)
print("Closing file")
infile.close()
infile = open(input())
total =0
value = int(line)
finally :
for line in infile :
```
```
Tester.py
```
except ValueError :
print("Error: Not an integer value.")
python; In the code below, we compute the sum of

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!