Sum numbers


I need to sum the objects in a text file. It's almost working, but I'm receiving an error that says 'invalid literal for int() wih base 10: 4.2' and can't figure out what I need to do?

def addNumbersAndSave(textfile,newFile):
    list1 = []
    sum1 = 0
    myfile = open(textfile)
    for i in myfile:
    for i in list1:
        i = int(i)
        sum1 += i
    f = open(newFile,"w")


Can you post a screenshot of the error? I have run your code in the codecademy environment as well as another environment ( and it seems to run fine, so I can't reproduce the problem.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.