On Sep 16, 2013, at 4:33 PM, William Bryant <gogobe...@gmail.com> wrote:
> Hey I am new to python so go easy, but I wanted to know how to make a program > that calculates the maen. > > List = [15, 6, 6, 7, 8, 9, 40] > def mean(): > global themean, thesum > for i in List: > thecount = List.count(i) > thesum = sum(List) > themean = thesum / thecount > > Why doesn't this work? > -- > https://mail.python.org/mailman/listinfo/python-list You've had a number of interesting and good responses, some holding your hand quite a bit, and others differently. I think there's a different way to learn what's going wrong, that ISN'T mentioned here, and for some people it's a quite effective method of learning. I'm a relatively recent import from the Smalltalk community, where this approach is more prevalent, I wish it were more so in the Python community. The way I suggest is to use a debugger. The nice thing about a debugger, is that you add a call to mean() at the end, put a breakpoint right there, run, and then you can visually walk through what it's doing. This can help find your bug, but probably also clarify how Python works in the first place. I use pycharm (anyone can use it for free). And there are probably others for free as well. -- https://mail.python.org/mailman/listinfo/python-list