python programming help

Alfred Canoy alred at guam.net
Tue Dec 7 07:35:20 CET 2004

```Hello,
Thanks for the input:-) I made a mean, median & mode program. I'm trying to figure how can I store this program in another file and opens the file to display. Any idea what to add in my source code. Thanks!

# compute the Mean, Median & Mode of a list of numbers:

sum = 0.0

print 'This program will take several numbers then average them'
count = input(' How many numbers would you like to sum: ')
current_count = 0

while current_count < count:
current_count = current_count + 1
num_list = []
while len (num_list) < count:
number = input ('Enter a number: ')
num_list.append(number)
print "Number", current_count,":",number
sum = sum + number

print num_list

def median(alist):
list_of_numbers = alist[:]
list_of_numbers.sort()
listLen = len(list_of_numbers)
middleIndex = (listLen - 1)/2
if listLen % 2 == 1:
# odd number of elements. return middle element
return list_of_numbers[middleIndex]
else:
# even number of element. return average of middle 2 elements
return (list_of_numbers[middleIndex] + list_of_numbers[middleIndex + 1]) / 2.0
if __name__ == '__main__':

def mode(alist):
start = 1
current = 0
new = 0
for i in alist:
if alist.count(i) >  start:
current = alist.count(i)
start = current
new = i
if new > 1:
return new
else:
return "All members of [%s] are modes." %alist
print 'mean:', sum/count
print 'median:',median (num_list)
print 'mode:',mode (num_list)

Al
_ _
_ _
Alfred Canoy
Agana, Guam
Pacific time
alred at guam.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20041207/156db6d6/attachment.html>
```