#This program will ask for a user to imput numbers. The numbers will then be calculated #to find the statistical mean, mode, and median. Finallly the user will be asked #if he would like to print out the answers. numbers = [ ] print 'Enter numbers to add to the list. (Enter 0 to quit.)' def getint(): return int(raw_input('Number? '))
numbers = sorted(iter(getint, 0)) numbers [2, 3, 5, 7] def variable_median(x): return sorted(x)[len(x)//2] def variable_mode(x): counts = {} for item in x: counts[x] = counts.get(x, 0) + 1 return sorted(counts, key=counts.__getitem__, reverse=True)[0] s = variableMean(numbers) y = variableMedian(numbers) t = variableMode (numbers) import pickle pickle.dump((s, y, t), file('avg.pickle', 'w')) print 'Thank you! Would you like to see the results after calculating' print 'The mode, median, and mean? (Please enter Yes or No)' print 'Please enter Yes or No:' if raw_input == yes: f = open("avg.py","r") avg.py = f.read() print 'The Mean average is:', mean print 'The Median is:', meadian print 'The Mode is:', mode I got the error: Traceback (most recent call last): File "C:\Python24\Lib\New Folder\Wade_StoddardSLP3-2.py", line 9, in ? numbers = sorted(iter(getint, 0)) File "C:\Python24\Lib\New Folder\Wade_StoddardSLP3-2.py", line 7, in getint return int(raw_input('Number? ')) TypeError: 'str' object is not callable and this one for my if statement: Traceback (most recent call last): File "C:\Python24\Lib\New Folder\Wade_StoddardSLP3-2.py", line 39, in ? if raw_input == Yes: NameError: name 'Yes' is not defined I cannot understand how I can define yes so that when they type yes the data is printed out. Also if they type no how do I make the program do nothing. Or is that just infered. -- http://mail.python.org/mailman/listinfo/python-list