Code:
def main():
myList=[]
choice = 0
while choice !='4':
choice= raw_input('1.add number to list\n2.get mean \n3.get median \n4.quit')
if choice == '1':
addNum(myList)
if choice == '2':
getMean(myList)
if choice == '3':
getMedian(myList)
if int(choice) < 0:
print "invalid input"
if int(choice) > 4:
print "invalid input"
##break
##input error messages
def addNum(myList):
while True:
num = raw_input("input new number:")
try:
num = int(num)
if num < 0:
raise ValueError
break
except:
print"invalid input"
myList.append(num)
def getMean(myList):
total = 0.0
for value in myList:
total = total + value
mean = total/len(myList)
print "the mean is:" , mean
def getMedian (myList):
index= 2
if len(myList)%2 == 0:
myMed = (myList[index] + myList[myMed-1])/2
else:
myList[len(myList)/2]
print myMed
Comment