I need help with my python program!!!! Please help!!!! get N numbers from a file
ID: 3779575 • Letter: I
Question
I need help with my python program!!!! Please help!!!!
get N numbers from a file, store the N numbers in an array, find the largest number, print the largest number to a different file or append to the original file, and print the list/array of numbers to the screen for the user.
You need to create the input file with N numbers.
You will read the input file name (and possible an output file, if you are writing the largest number to a different file, rather than appending to the input file) as a command line argument(s).
Explanation / Answer
import sys
inm = sys.argv[1]
f = open(inm,"r")
mx = -1*sys.maxint
for l in f.readlines():
l = l[0:-1]
l = l.split()
for a in l:
a = int(a)
if(a>mx):
mx = a
f.close()
if(len(sys.argv)==3):
outm = sys.argv[2]
else:
outm = sys.argv[1]
f = open(outm,"a")
f.write(" "+str(mx))
f.close()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.