fork download
  1. def mean1(mylist):
  2. mysum = 0
  3. for i in range(len(mylist)):
  4. mysum += mylist[i]
  5. return float(mysum) / len(mylist)
  6.  
  7. def mean2(mylist):
  8. mysum = 0
  9. for value in mylist:
  10. mysum += value
  11. return float(mysum) / len(mylist)
  12.  
  13. def mean3(mylist):
  14. return float(sum(mylist)) / len(mylist)
  15.  
  16. mylist = [1, 2, 3, 4]
  17. print mean1(mylist), mean2(mylist), mean3(mylist)
Success #stdin #stdout 0.01s 7692KB
stdin
Standard input is empty
stdout
2.5 2.5 2.5