# File: ChapterIOFiles/findMax.py """ Reads a text file of Ints. Each on a different line: 2 7 8 3 Finds sum and max. Use functions sum(List) and max(list) and list.index(item) Run: ['2\n', '7\n', '8\n', '3'] [2, 7, 8, 3] 20 max= 8 index= 2 """ def main(): fin = open("Texts/myints.txt", "r" ) lineList = fin.readlines() fin.close() print(lineList) # ['2\n', '7\n', '8\n', '3'] line = [int(x) for x in lineList] # conversion to int print(line) # [2, 7, 8, 3] print(sum(line)) maxnum = max(line) im = line.index( maxnum ) # find the index i of maxNum print("max=", maxnum, "\nindex=",im) main()