Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #97118

Re: Problem to calculate the mean in version 3.4

From Peter Otten <__peter__@web.de>
Subject Re: Problem to calculate the mean in version 3.4
Date 2015-09-25 09:09 +0200
Organization None
References <F4A60959-BFA5-46CC-B83C-9D50CE2D1D00@yahoo.co.uk>
Newsgroups comp.lang.python
Message-ID <mailman.164.1443164969.28679.python-list@python.org> (permalink)

Show all headers | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Problem to calculate the mean in version 3.4 Peter Otten <__peter__@web.de> - 2015-09-25 09:09 +0200

csiph-web