In [1]:
def mean(nums):
    bot = len(nums)
    it = 0
    top = 0
    while it < len(nums):
        top += nums[it]
    return float(top) / float(bot)

a_list = [1, 2, 3, 4, 5, 6, 10, "one hundred"]
# Won't run!
#mean(a_list)

In [2]:
def mean(nums):
    bot = len(nums)
    it = 0
    top = 0
    print("Still Running at line 5")
    while it < len(nums):
        top += nums[it]
        print(top)
    return float(top) / float(bot)

a_list = [1, 2, 3, 4, 5, 6, 10, "one hundred"]
# Won't run!
#mean(a_list)

In [3]:
def mean(nums):
    top = sum(nums)
    bot = len(nums)
    return float(top) / float(bot)

a_list = [1, 2, 3, 4, 5, 6, 10, "one hundred"]
mean(a_list)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-e2cb268a9d7e> in <module>()
      5 
      6 a_list = [1, 2, 3, 4, 5, 6, 10, "one hundred"]
----> 7 mean(a_list)

<ipython-input-3-e2cb268a9d7e> in mean(nums)
      1 def mean(nums):
----> 2     top = sum(nums)
      3     bot = len(nums)
      4     return float(top) / float(bot)
      5 

TypeError: unsupported operand type(s) for +: 'int' and 'str'

In [4]:
import pdb

# uncomment to run pdb
#pdb.set_trace()
a_list = [1, 2, 3, 4, 5, 6, 10, "one hundred"]
mean(a_list)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-98ad7040ae2e> in <module>()
      4 #pdb.set_trace()
      5 a_list = [1, 2, 3, 4, 5, 6, 10, "one hundred"]
----> 6 mean(a_list)

<ipython-input-3-e2cb268a9d7e> in mean(nums)
      1 def mean(nums):
----> 2     top = sum(nums)
      3     bot = len(nums)
      4     return float(top) / float(bot)
      5 

TypeError: unsupported operand type(s) for +: 'int' and 'str'

In [5]:
a_list = [1, 2, 3, 4, 5, 6, 10, 100]
result = mean(a_list)
print(result)


16.375