211k views
1 vote
A file named numbers.txt contains an unknown number of lines, each consisting of a single positive integer. Write some code that reads through the file and stores the largest number read in a variable named maxvalue.

** PYTHON**

A file named numbers.txt contains an unknown number of lines, each consisting of a-example-1
User CNoob
by
5.3k points

1 Answer

7 votes

f = open("numbers.txt", "r")

lst = [int(x) for x in f.read().splitlines()]

maxvalue = max(lst)

This works for me. Best of luck. If you want to test the code in an ide, use print(maxvalue) at the end of the code to see the value of your maxvalue variable.

User Neptune
by
4.7k points