# [Python-Help] (fwd)

Robert Brewer fumanchu at amor.org
Sun Dec 5 06:14:15 CET 2004

```Alfred Canoy wrote:
>  I'm just new to programming and would like to ask for help..
>
> Build a module that contains three functions that do the following:
>
>       a.. Compute the average of a list of numbers
>       b.. Finds the statistical median value of a list of numbers
>       c.. Finds the mode of a list of numbers
>
> Can you please give me clue how I should start solving the
> following problem
> below? Here's the source code that I did so far:
>
> # compute the average of a list of numbers:
> # Keeps asking for numbers until 0 is entered
> # Prints the average value
>
> count = 0
> sum = 0
> number = 1
>
> print 'Enter 0 to exit the loop'
> while number != 0:
>     number = input ('Enter a number: ')
>     count = count + 1
>     sum = sum + number
> count = count -1
> print ' The average is:', sum/count

Looks good to me (well, I'd write the loop differently, but...). What is
happening that you dislike?

>>> count = sum = 0
>>> number = 1
>>> while number != 0:
... 	number = input('Enter a number: ')
... 	count += 1
... 	sum += number
...
[Enters 3, 5, and 7]
>>> sum, count
(15, 4)
>>> count -= 1
>>> sum/count
5

Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org

```