Reading a file and using a loop to output the integers while displaying the largest number python
Question: The program should output all of the integers, one per line, with no blank
lines between each line. This program should also output the largest random
number that was on file.

    
    
    myfile = open('mynumbers.txt', 'r')
    
    lines = myfile.readline()
    
    print(lines)
    

I have gotten that far and I'm stuck. I have literally been sitting here for 6
hours and I don't know what the deal is!

I need help using a loop to read and process the `mynumbers.txt` file and then
it also has to display the largest number that was in the group.

    
    
    myfile = open('mynumbers.txt', 'w')
    
    import random
    num = random.randint(6, 12)
    print(num)
    for num in range(num):
        myfile.write(str(random.randrange(10, 20)))
    

I also keep getting this error after I try everything.

ValueError: invalid literal for int() with base 10: '16 19 11 18 14 11 15 18
18 16 20 16'

Sorry everyone i'm new to the site!


Answer: `.readline()` only read **one** line.

You should use `.readlines()` if you want to get all the lines of your file.

Moreover, it is better to open your file using `with`.

    
    
    with open('filename.txt') as fp:
        lines = fp.readlines()
    # Do something with the lines
    

See [the
documentation](https://docs.python.org/3.4/tutorial/inputoutput.html#methods-
of-file-objects) for more information.

