How do I add things up in a list that I’m getting from a file thats being read in?

I’m sorry if its been asked before but I’m a little stumped. I’m reading in a file that has me display the info line by line. On the third line I’m expected readline() and then add the numbers that are in that line to a single outcome. I tried adding the line to a list so i can split it and then use sum method but i keep getting and error

with open("January.txt","r") as infile:
        line1 = infile.readline()
        print("Account Number:",line1[0:3]+"-"+line1[3:5]+"-"+line1[5:8])
        line2 = infile.readline()
        print(f"Beginning Balance:${line2}")
        withdrawal = []
        for i in range (1):
            line3 = infile.readline().strip()

I used a for loop to avoid the enter i get in the line. I tried converting to int but would get errors as well. This is the information on the file I’m trying to read


Read more here:

Content Attribution

This content was originally published by Kei at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: