I am trying to get the sum of my list in python This is my code

0 votes
import csv
file1 = "Root/20Cent.txt"
rows = []
result = 0
i = 0
with open(file1) as csvfile:
    infile = csv.reader(csvfile)
    header = next(infile)
    for row in infile:
        rows.append(row)
        for i in infile:
            result = result + i
            i = i + 1
            print(str(result))

Error given:

result = result + i TypeError: unsupported operand type(s) for +: 'int' and 'list'

What am I doing wrong or not including that would help me read my file element by element and add them all together?
Apr 24, 2022 in Python by kat

edited Mar 4, 2025 320 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP