Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.046 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; '16,': 0.03; 'differently.': 0.09; 'run,': 0.09; 'wrong,': 0.09; 'subject:How': 0.10; 'python': 0.11; 'def': 0.12; 'suggest': 0.14; 'breakpoint': 0.16; 'bug,': 0.16; 'calculates': 0.16; 'debugger,': 0.16; 'debugger.': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'hey': 0.18; 'community,': 0.19; 'import': 0.22; 'community.': 0.22; 'header:In-Reply-To:1': 0.27; 'received:172.16': 0.29; "doesn't": 0.30; 'list:': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'easy,': 0.31; 'end,': 0.31; 'sep': 0.31; 'probably': 0.32; 'quite': 0.32; 'url:python': 0.33; 'there,': 0.34; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'list': 0.37; 'message- id:@gmail.com': 0.38; 'work?': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'how': 0.40; 'free': 0.61; 'mentioned': 0.61; 'new': 0.61; 'effective': 0.61; 'first': 0.61; "you've": 0.63; 'header:Message-Id:1': 0.63; 'more': 0.64; 'different': 0.65; 'holding': 0.65; 'relatively': 0.65; 'wish': 0.70; 'walk': 0.74; 'hand': 0.80; 'william': 0.81; 'visually': 0.84; '2013,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=97WE5bb7f1LoRPP9dC4DeeqCzoy24q6r0FcyUnhSNeo=; b=Ac3dobS0ppHsy2wkA10g11JXOdKH0xMG9WoM57Kes9KF3vQAc1ZJ+AroiflckMgX2/ tAvJYnpYKbm152JJbgyZkerdTxKs7SJbQ+v468V1YGNauklzeJ22O7P+fEWHvDvheL9F ShkA0bgP2wpo7aWPPhQb0G7ZLQAODrEnKTJKxkwrgYTElxo/PGMvUIR3vi11eElamYlw GsySd0PX5EWVWeZaR6EXjfYTq4qozMG2iREJvKAIrgGBvKo9sU4d75gJIGPAZivXNSp8 G8y3WrFyNow+0hERHSnFWnUbRv9LJl6wSCTefnvFb55PEYTqVFNn8tbC5uNxcGCi1Hi8 BBCw== X-Received: by 10.68.236.168 with SMTP id uv8mr14266812pbc.124.1379431539550; Tue, 17 Sep 2013 08:25:39 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) Subject: Re: How do I calculate a mean with python? From: Travis Griggs In-Reply-To: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> Date: Tue, 17 Sep 2013 08:25:35 -0700 Content-Transfer-Encoding: quoted-printable References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> To: python-list@python.org X-Mailer: Apple Mail (2.1508) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1379431547 news.xs4all.nl 15986 [2001:888:2000:d::a6]:36354 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54314 On Sep 16, 2013, at 4:33 PM, William Bryant wrote: > Hey I am new to python so go easy, but I wanted to know how to make a = program that calculates the maen. >=20 > List =3D [15, 6, 6, 7, 8, 9, 40] > def mean(): > global themean, thesum > for i in List: > thecount =3D List.count(i) > thesum =3D sum(List) > themean =3D thesum / thecount >=20 > Why doesn't this work? > --=20 > 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.=20