Question: PYTHON-JUPYTER NOTEBOOK Write a program that from a file with numbers (one number per line): reads the file calculates the maximum and minimum stores the

PYTHON-JUPYTER NOTEBOOK

Write a program that from a file with numbers (one number per line):

  • reads the file
  • calculates the maximum and minimum
  • stores the max and min in another file (the first line of the file with the max and the second line with the min)

This is what I have done so far, but it is not working:

file_a = open(input("File A:"),"r")

file_b=open(input("File B:"),'w')

num=[]

for line in file_a:

lines =[line.strip(' ') for line in file_a.readlines()]

print(lines)

for i in lines:

num.append(int(i))

newnum=[]

newnum.append(max(num))

newnum.append(min(num))

print(num)

file_b.write(str(newnum))

print(newnum)

print(min(num))

print(max(num))

file_a.close

file_b.close

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 Databases Questions!