Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97118 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2015-09-25 09:09 +0200 |
| Last post | 2015-09-25 09:09 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Problem to calculate the mean in version 3.4 Peter Otten <__peter__@web.de> - 2015-09-25 09:09 +0200
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2015-09-25 09:09 +0200 |
| Subject | Re: Problem to calculate the mean in version 3.4 |
| Message-ID | <mailman.164.1443164969.28679.python-list@python.org> |
Michel Guirguis wrote: > I have downloaded the version 3.4 and I have a problem to calculate the > mean. The software does not recognise the function mean(). I am getting > the following error. > >>>> mean([1, 2, 3, 4, 4]) > Traceback (most recent call last): > File "<pyshell#4>", line 1, in <module> > mean([1, 2, 3, 4, 4]) > NameError: name 'mean' is not defined > > Could you please help. Is it possible to send me the version that > calculate statistics. The help for the statistics and other modules assumes basic knowledge of Python. I recommend you read the tutorial or any other introductory text on Python before you proceed. Regarding your actual question: before you can use a function you have to import it. There are two ways: (1) Recommended: import the module and use the qualified name: >>> import statistics >>> statistics.mean([1, 2, 3, 4, 4]) 2.8 (2) Import the function. Typically done when you want to use it in the interactive interpreter, not in a script. >>> from statistics import mean >>> mean([1, 2, 3, 4, 4]) 2.8
Back to top | Article view | comp.lang.python
csiph-web