Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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