Write a function called csv_sum that takes a filename and returns the sum of all of the numbers in the file. The numbers are in csv format. For instance, if the contents of the file are: 12,3,2 -5 10,20,-10,8.3 Then the function should return 40.3.

Respuesta :

Answer:

Explanation:

def csv_sum(filename):

   total = 0

   try:

       f = open(filename)

       for line in f:

           words = line.strip().split(",")

           for word in words:

               total += float(word)

       f.close()

   except FileNotFoundError:

       pass

   return total