Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 9th International Conference Dasfaa 2004 Jeju Island Korea March 2004 Proceedings Lncs 2973

Authors: YoonJoon Lee ,Jianzhong Li ,Kyu-Young Whang

2004th Edition

3540210474, 978-3540210474

More Books

Students also viewed these Databases questions

Question

difference between program and algorithms

Answered: 1 week ago

Question

nutcracker production how do you use grant given for a production

Answered: 1 week ago