Respuesta :

In Python, assume that a file containing a series of integers is named numbers.txt and exist on the computer's disk. Write a program that reads the entire numbers store in the file and calculates their total.

Here is what I have written but it does not run:  

def. main():

   out file=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

Learn more:

  • The sum of three consecutive integers is 186. what are the integers

        brainly.com/question/1768254

Keywords: python, integers, computer, numbers, program

To find the maximum value from a list of single positive integers of a file following procedure is used:

First open the file and initialize the maxvalue variable. Now, begin the for loop that will compare the maxvalue variable with the value stored in the file. If the value of maxvalue variable is less than the stored value of the file then store it in maxvalue variable otherwise not store it. The comparison will continue till the last value of the file and finally display the maximum value.

Further explanation:

The python code to calculate the maximum value from a file is as shown below:

Code:

#First open the file  in the read mode

file = open('numbers.txt', 'r');

#Initialize the variable

maxvalue=0

#Begin the for loop.

for line in file:

#Compare the values of text file from maxvalue variable and find the maximum value

if maxvalue <= int (line):

#Store the maximum value in the variable maxvalue.

maxvalue = int (line)

#Display the maximum value of the numbers.txt file.

print ('maxvalue is:',maxvalue)

The content of the text file is as shown below:

Text file "numbers.txt"

3

6

8

1

6

9

4

7

2

Output:

maxvalue is : 9

Learn more:

1. How does coding work on computers?  brainly.com/question/2257971

2. Prediction accuracy of a neural network depends on _______________ and ______________. brainly.com/question/10599832  

Answer details:

Grade: College Engineering

Subject: Computer Science

Chapter: Python Programming

Keyword:

python, input, output, programming, statements,  char, int, variables, maxvalue, open, file, loop, text file, line, numbers