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()
        account.append(line1)
        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()
            withdrawal.append(line3)
            print(withdrawal)

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

21728392
1200.56
19.18,29.15,78.75,212.10
100.20,410.29


Read more here: https://stackoverflow.com/questions/64392752/how-do-i-add-things-up-in-a-list-that-i-m-getting-from-a-file-thats-being-read-i

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: