see http://teaching.software-carpentry.org/wp-content/uploads/2012/08/guzdial.pdf
Test where students miserably fail: calculate average of inputted positive numbers, stopping if 99999 is inputted
In [1]:
from operator import add
print("numbers followed by enter - (stop by typing 99999)")
numbers = []
while True:
i = raw_input("? ")
try:
i = int(i)
except:
continue
if i == 99999:
break
if i > 0:
numbers.append(i)
print("average: %s" % (reduce(add, numbers) / float(len(numbers))))
In [ ]: