Feb-05-2018, 02:52 AM
import statistics import math def load_stats(filename): #load file containing integers #integers are separated by a space data_list = [] with open('stats.txt', 'r') as f: for line in f: (x) = line.strip().split(',') data_list+=[x] data_list.sort() return (data_list) def main(): done = False while not done: (data_list) = load_stats('stats.txt') print ('Choose an option:') print ('1. Load data') print ('2. Display computed statistics') print ('3. Save computed statistics') print ('4. Exit') user = input(str('Choice:')) if user == '1': file_name = input('Enter the name of the file:') print ('Data read successfully') elif user == '2': print ('Below are the computed values:') print ('Min =', min(data_list)) print ('Max =', max(data_list)) elif user == '3': new_file = input ('Enter the name of the file:') print ('Result saved successful.') elif user == '4': print ('Goodbye!') done = True main()I am having issues with it just printing out the min and max value. It gives this to me instead.
Choose an option:
1. Load data
2. Display computed statistics
3. Save computed statistics
4. Exit
Choice:2
Below are the computed values:
Min = ['87', ' 63', ' 100', ' 94', ' 56', ' 77', ' 60', ' 72', ' 99', ' 83']
Max = ['87', ' 63', ' 100', ' 94', ' 56', ' 77', ' 60', ' 72', ' 99', ' 83']
Choose an option:
I also have to add in mean and median but cannot seem to find the right modules that I need to call so they work.
I have tried both import statistics and import math.
I am on python 3.
Attached Files