# Array2 Example # Read an array from a file, then compute the # sum of the array. Use two methods read_array # and sum_array to accomplish this. # Define method to read array. def read_array(the_file_name): values = [ ] f = open(the_file_name, "r") line = f.readline( ) while line: values.append(float(line.strip( ))) line = f.readline( ) return values # Define method to compute sum of array. def sum_array(the_array): sum = 0.0 for x in the_array: sum += x return sum # Use methods defined below to read and # compute sum of array. These methods must # be defined before using them values = read_array("values1.txt") print("Sum = {0:.2f}".format(sum_array(values)))