Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #54258
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.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 | <jugurtha.hadjar@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.021 |
| X-Spam-Evidence | '*H*': 0.96; '*S*': 0.00; 'suppose': 0.07; 'occurrences': 0.09; 'subject:How': 0.10; 'python': 0.11; 'def': 0.12; 'calculates': 0.16; 'compute': 0.16; 'elements,': 0.16; 'mean,': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'hey': 0.18; 'all,': 0.19; 'header:User-Agent:1': 0.23; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'list:': 0.30; 'gives': 0.31; 'easy,': 0.31; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'list': 0.37; 'message-id:@gmail.com': 0.38; 'work?': 0.38; 'to:addr:python- list': 0.38; 'list,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'then,': 0.60; 'new': 0.61; 'numbers': 0.61; 'sum': 0.64; 'william': 0.81; 'divided': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=RXas8FHs2Li4YGaxUmk31cRVVH/UQkZ7MLcrQrQGWZ8=; b=EgVxXxlzmrd5wOmSlE0ogBhdNJpQYU/l4UjOggr5rWrG6C0f6kyiY5+hFzZogOCJZf mGkDzOrL2+xlQvd2FLPObohhFqKcwn9ybAWBQMTthcoF3Kz3rZibHCdMF2TWHqI6UjpA zYhEPwhguJBGeZ7wqIYgmd0DY6tlbVHP3hJGdlBBMNrz9+eJCMcrrvw6h2Vu3CaDxt/7 FBAx01A4X3v120S99GrvQcm/iqRpZ7GrhEPSj2xiXKh7BI+1lyt6cIHJ4dNh7ZvXrCZX 1ZNSjr0vyVFEcihX0UQLatPQSsIDKiXwrYcU44kNdi09Wyb5PvMYGM4twNMIoDs4eHrv MVvA== |
| X-Received | by 10.14.122.132 with SMTP id t4mr47351942eeh.20.1379376523077; Mon, 16 Sep 2013 17:08:43 -0700 (PDT) |
| Date | Tue, 17 Sep 2013 01:08:42 +0100 |
| From | Jugurtha Hadjar <jugurtha.hadjar@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130803 Thunderbird/17.0.8 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: How do I calculate a mean with python? |
| References | <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> |
| In-Reply-To | <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.43.1379376531.18130.python-list@python.org> (permalink) |
| Lines | 28 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1379376531 news.xs4all.nl 15898 [2001:888:2000:d::a6]:51213 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:54258 |
Show key headers only | View raw
On 09/17/2013 12:33 AM, 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. > > 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? > You want to compute the arithmetic mean, I suppose .. Which is the sum of all, divided by the number of samples. i.e: If you have n numbers or elements, your mean (arithmetic) would be mean = sum(elements)/n. Right ? And then, n also doesn't need to be in the loop and list.count(i) gives the occurrences of i in your list, which you don't need. list.count(15) gives 1. thesum/list.count(15) doesn't change. -- ~Jugurtha Hadjar,
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How do I calculate a mean with python? William Bryant <gogobebe2@gmail.com> - 2013-09-16 16:33 -0700
Re: How do I calculate a mean with python? Jugurtha Hadjar <jugurtha.hadjar@gmail.com> - 2013-09-17 00:52 +0100
Re: How do I calculate a mean with python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-16 23:55 +0000
Re: How do I calculate a mean with python? MRAB <python@mrabarnett.plus.com> - 2013-09-17 01:01 +0100
Re: How do I calculate a mean with python? Jugurtha Hadjar <jugurtha.hadjar@gmail.com> - 2013-09-17 01:08 +0100
Re: How do I calculate a mean with python? Cameron Simpson <cs@zip.com.au> - 2013-09-17 09:59 +1000
Re: How do I calculate a mean with python? Dave Angel <davea@davea.name> - 2013-09-17 00:50 +0000
Re: How do I calculate a mean with python? Travis Griggs <travisgriggs@gmail.com> - 2013-09-17 08:25 -0700
Re: How do I calculate a mean with python? William Bryant <gogobebe2@gmail.com> - 2013-09-17 12:44 -0700
Re: How do I calculate a mean with python? William Bryant <gogobebe2@gmail.com> - 2013-09-17 12:45 -0700
Re: How do I calculate a mean with python? William Bryant <gogobebe2@gmail.com> - 2013-09-17 13:10 -0700
Re: How do I calculate a mean with python? Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-17 17:02 -0400
Re: How do I calculate a mean with python? MRAB <python@mrabarnett.plus.com> - 2013-09-17 22:26 +0100
Re: How do I calculate a mean with python? William Bryant <gogobebe2@gmail.com> - 2013-09-17 14:31 -0700
Re: How do I calculate a mean with python? Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-17 19:49 -0400
Re: How do I calculate a mean with python? Bryan Britten <britten.bryan@gmail.com> - 2013-09-17 18:53 -0700
csiph-web