Question: A file's name is read from input. The file is opened and fig _ file is assigned with the file object. Each line in fig

A file's name is read from input. The file is opened and fig_file is assigned with the file object. Each line in fig_file contains an integer representing the number of figs bought in a day. Use a loop to read each line of fig_file. Inside the loop, assign sum_of_figs with the sum of all the integers in fig_file.
Click here for exampleEx: If the input is data1.txt and:
Contents of file data1.txt3
14
7
6
then the output is:
Total number of figs bought: 30
main.pydata1.txtdata2.txtdata3.txt
fig_file = open(input())
''' Your code goes here '''
fig_file.close()
print(f'Total number of figs bought: {sum_of_figs}')

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!