Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Python, assume that a dile containing a series of integers is named numbers.txt and exisist on the computer's disk. Write a program that reads
In Python, assume that a dile containing a series of integers is named numbers.txt and exisist on the computer's disk. Write a program that reads all of the numbers store in the file and calculates their total.
Here is what I have written but it does not run:
def main(): outfile=open('numbers.txt','r') temp=outfile.readline() total=0 while temp!='': t=int(temp) total=total+i temp=outfile.readline() outfile.close() print('Total sum is:',total) main()
Text file is a file named numbers.txt with the numbers 1-50 in it.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started