My text file has five numbers, 1-5 I don't what the problem is. I've written the file using Word (saved as .txt ) as well as TextEdit Python 3.4.1 on a Mac
Here's the code: # Richard Dillon # This program reads data from a .txt file and calculates a total # data in text file: 1,2,3,4 and 5 for a total of 15 # error message: Non-numeric data found in the file def main(): total = 0.0 try: infile = open('/Users/richarddillon/Desktop/numbers.txt', 'r') for line in infile: amount = float(line) total += amount infile.close() print(format(total, ',.2f')) except IOError: print('An error occured trying to read the file.') except ValueError: print('Non-numeric data found in the file.') except: print('An error occured.') main() _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor