Dec-30-2016, 02:37 PM
(This post was last modified: Dec-30-2016, 02:37 PM by ichabod801.)
If you use csv, the reading and writing is much simpler:
import csv test = [[2, 3, 5, 7], [11, 13, 17, 19]] output = open('forum.txt', 'w') writer = csv.writer(output) for row in test: writer.writerow(row) output.close() infile = open('forum.txt') reader = csv.reader(infile) for row in reader: nums = [int(x) for x in row] print(nums) print(sum(nums)) infile.close()Also, you can put everything in the same loop, so you don't have to rerun the program each time:
user_input = '' while user_input ne 'q': user_input = ('Please enter (w)rite, (c)ompress, (d)ecompress, or (q)uit: ').lower() if user_input == 'w': # write elif user_input == 'c': # compress elif user_input == 'd': # decompress elif user_input != 'q': print('Please enter w, c, d, or q.')
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures