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


Groups > comp.lang.python > #54252 > unrolled thread

How do I calculate a mean with python?

Started byWilliam Bryant <gogobebe2@gmail.com>
First post2013-09-16 16:33 -0700
Last post2013-09-17 18:53 -0700
Articles 16 — 9 participants

Back to article view | Back to comp.lang.python


Contents

  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

#54252 — How do I calculate a mean with python?

FromWilliam Bryant <gogobebe2@gmail.com>
Date2013-09-16 16:33 -0700
SubjectHow do I calculate a mean with python?
Message-ID<571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com>
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?

[toc] | [next] | [standalone]


#54254

FromJugurtha Hadjar <jugurtha.hadjar@gmail.com>
Date2013-09-17 00:52 +0100
Message-ID<mailman.41.1379375545.18130.python-list@python.org>
In reply to#54252
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?
>


Hello, William..

How about you try to execute one bit of your program, and if that works, 
try to add to it.

Try

list = [15, 6]
list.count(1)

And see if what it gives you back is what you expected. If not, why ?



-- 
~Jugurtha Hadjar,

[toc] | [prev] | [next] | [standalone]


#54255

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-09-16 23:55 +0000
Message-ID<52379a5b$0$29988$c3e8da3$5496439d@news.astraweb.com>
In reply to#54252
On Mon, 16 Sep 2013 16:33:35 -0700, 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?

Let me start by saying that the above is not "best practice" for how to 
write functions, and I'll explain why later, but for now I'll just fix 
the problem with the calculation.

You have List = [15, 6, 6, 7, 8, 9, 40] and then the mean function walks 
through each of the items 15, 6, 6, 7, ... counting how many times that 
item is found:

for i in List:
    thecount = List.count(i)
    thesum = sum(List)


So the first time, i gets the value 15, thecount calculates 
List.count(15) which is 1, thesum calculates sum(List) which is 91, and 
the end of the loop is reached.

The second time around, i gets the value 6, then thecount calculates 
List.count(6) which is 2, thesum calculates sum(List) *again*, which is 
still 91, and the end of the loop is reached.

Third time around, i gets the value 6 again, thecount again gets the 
value 2, thesum yet again sums up List which still hasn't changed, so yet 
again gets 91.

And so on, and so on, until the last iteration, where i gets the value 
40, thecount calculates List.count(40) which is 1, thesum re-calculates 
the sum yet again, still getting the exact same result 91, and finally 
the for-loop comes to an end.

Now the final calculation occurs:

themean = thesum/thecount

which is 91/1 or just 91.

What do you actually want? It's much simpler: you want to count the 
*total* number of items, 7, not by counting each item individually. The 
total number of items is given by the length of the list:

len(List)

returns 7. And you want to sum the list once, there's no need to sum it 7 
times. So the first step is to get rid of the for-loop, just calculate 
thesum = sum(List) once, and thecount = len(List) once.

Once you've done that, please write back with your new code, because I 
think there will be some more improvements to be made.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#54256

FromMRAB <python@mrabarnett.plus.com>
Date2013-09-17 01:01 +0100
Message-ID<mailman.42.1379376117.18130.python-list@python.org>
In reply to#54252
On 17/09/2013 00:33, 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

You're iterating through every number in the list...

>      for i in List:

counting how many times each number occurs in the list:

>          thecount = List.count(i)

This line calculates the sum of the numbers on every iteration:

>          thesum = sum(List)

This line divides the sum of the numbers by the last count:

>      themean = thesum / thecount
>
> Why doesn't this work?
>
It does work; it just doesn't calculate the mean!

What you end up with is:

themean = sum(List) / List.count(40)

What you _really_ want is the sum of the numbers divided by the
number of numbers (i.e. the length of the list).

[toc] | [prev] | [next] | [standalone]


#54258

FromJugurtha Hadjar <jugurtha.hadjar@gmail.com>
Date2013-09-17 01:08 +0100
Message-ID<mailman.43.1379376531.18130.python-list@python.org>
In reply to#54252
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,

[toc] | [prev] | [next] | [standalone]


#54259

FromCameron Simpson <cs@zip.com.au>
Date2013-09-17 09:59 +1000
Message-ID<mailman.44.1379377672.18130.python-list@python.org>
In reply to#54252
On 16Sep2013 16:33, William Bryant <gogobebe2@gmail.com> 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?

Well:

  - always include the output you get from your program, and say
    why you think it is incorrect

  - just style: we tend to name variables in lower case in Python, and
    classes with an upper case letter; "List" is a bit odd (but
    "list" is taken; how about "values"?)

  - more than style: WHY are you using global variables; just return the mean
    from the function!

  - teh variable "List" inside the function is _local_; your function does not
    accept a parameter

  - sum(List) sums the whole list
    you run it many times
    why?

  - what do you think "count()" does?

  - you should print i, thecount and thesum on each iteration of
    the list; it will help you see what your function is doing, and
    therefore to figure out what it is doing wrong

I would write a mean like this:

    def mean(values):
      return sum(values) / len(values)

There are circumstances where that is simplistic, but it is the classic
definition of the mean.

Cheers,
-- 
Cameron Simpson <cs@zip.com.au>

Microsoft Mail: as far from RFC-822 as you can get and still pretend to care.
      - Abby Franquemont-Guillory <abbyfg@tezcat.com>

[toc] | [prev] | [next] | [standalone]


#54260

FromDave Angel <davea@davea.name>
Date2013-09-17 00:50 +0000
Message-ID<mailman.45.1379379029.18130.python-list@python.org>
In reply to#54252
On 16/9/2013 19:33, 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?

Besides all the other comments, you also neglected calling this
function.

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#54314

FromTravis Griggs <travisgriggs@gmail.com>
Date2013-09-17 08:25 -0700
Message-ID<mailman.80.1379431547.18130.python-list@python.org>
In reply to#54252
On Sep 16, 2013, at 4:33 PM, William Bryant <gogobebe2@gmail.com> 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?
> -- 
> 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. 

[toc] | [prev] | [next] | [standalone]


#54328

FromWilliam Bryant <gogobebe2@gmail.com>
Date2013-09-17 12:44 -0700
Message-ID<91fe5a4b-45f6-4903-bd1a-ebf5c82ebb48@googlegroups.com>
In reply to#54252
Sorry guys, I didn't read anything u said. Because I just figured it out on my own :)
I'll read it now. But u can check out my program I have done so far (It works but I think it needs some tidying up.) :)

Thanks!

[toc] | [prev] | [next] | [standalone]


#54329

FromWilliam Bryant <gogobebe2@gmail.com>
Date2013-09-17 12:45 -0700
Message-ID<b43b75cf-d8b6-4099-b209-04297be134be@googlegroups.com>
In reply to#54252
'''#*************************************************************************'''
#* Name:        Mode-Median-Mean Calculator                                   *#
#*                                                                            *#
#* Purpose:     To calculate the mode, median and mean of a list of numbers   *#
#*              and the mode of a list of strings because that is what we are *#
#*              learning in math atm in school :P                             *#
#*                                                                            *#
#* Author:      William Bryant                                                *#
#*                                                                            *#
#* Created:     11/09/2013                                                    *#
#*                                                                            *#
#* Copyright:   (c) William 2013                                              *#
#*                                                                            *#
#* Licence:     IDK :3                                                        *#
'''**************************************************************************'''



#-----#                   ~~Import things I am using~~                   #-----#

#         |
#        |
#       \/

import time
import itertools



#-----#        ~~Variables that I am using, including the list.~~        #-----#

#         |
#        |
#       \/

List = []
NumberOfXItems = []
themode = None
themean = None
count = None

#-----#                   ~~Functions that I am using.~~                 #-----#

#         |
#        |
#       \/

def HMNs():
    global TheStr, user_inputHMNs, List_input, List
    user_inputHMNs = input("You picked string. This program cannot calculate the mean or median, but it can calculate the mode. :D  How many strings are you using in your list? (Can not be a decimal number)  \nEnter:  ")
    user_inputHMNs
    time.sleep(1.5)
    TheStr = int(user_inputHMNs)
    for i in range(TheStr):
        List_input = input("Enter your strings. (One in each input field):  ")
        List.append(List_input)
        print("Your list -> ", List)
        if List.count == int(user_inputHMNs):
            break
        mode()
        mean()
        print("\n*Mode*:", themode)
        print("*Median*:",  "<Coming soon!>\n")
        print("*Mean*:",    themean)

def HMNn():
    global TheNum, user_inputHMNn, List_input, List
    user_inputHMNn = input("You picked number. :D How many numbers are you using in your list? (Can not be a decimal number) \nEnter:  ")
    user_inputHMNn
    time.sleep(1.5)
    TheNum = int(user_inputHMNn)
    for i in range(TheNum):
        List_input = input("Enter your numbers. (One in each input field):  ")
        List_input = int(List_input)
        List.append(List_input)
        print("\nYour list -> ", List)
        if List.count == int(user_inputHMNn):
            break
        mode()
        mean()
        print("\n*Mode*:", themode)
        print("*Median*:",  "<Coming soon!>")
        print("*Mean*:",    themean)

def NOS():
    while True: # Loops forever (until the break)
        answer = input("Does your list contain a number or a string?  \nEnter: ")
        answer = answer.lower()
        if answer in ("string", "str", "s"):
            HMNs()
            break
        elif answer in ("number", "num", "n", "int"):
            HMNn()
            break
        elif answer in ("quit", "q"):
            break  # Exits the while loop
        else:
            print("You did not enter a valid field, :P Sorry.  \nEnter: ")
    time.sleep(1.5)

def mean():
    global themean
    thecount = []
    for i in List:
        thecount.append(List.count(i))
        thesum = sum(List)
    thecount = sum(thecount)
    themean = thesum / thecount

def mode():
    global themode
    max_occurrences = 0
    themode = None
    for i in List:
        thecount = List.count(i)
        if thecount > max_occurrences:
            max_occurrences = thecount
            themode = i



#-----#               ~~The functions which need calling~~               #-----#

#         |
#        |
#       \/

NOS()

[toc] | [prev] | [next] | [standalone]


#54330

FromWilliam Bryant <gogobebe2@gmail.com>
Date2013-09-17 13:10 -0700
Message-ID<1540971c-7868-4f01-be3b-98fd5dffa985@googlegroups.com>
In reply to#54252
Ok I think I've fixed it thanks I read everything.

'''**************************************************************************'''
#* Name:        Mode-Median-Mean Calculator                                   *#
#*                                                                            *#
#* Purpose:     To calculate the mode, median and mean of a list of numbers   *#
#*              and the mode of a list of strings because that is what we are *#
#*              learning in math atm in school :P                             *#
#*                                                                            *#
#* Author:      William Bryant                                                *#
#*                                                                            *#
#* Created:     11/09/2013                                                    *#
#*                                                                            *#
#* Copyright:   (c) William 2013                                              *#
#*                                                                            *#
#* Licence:     IDK :3                                                        *#
'''**************************************************************************'''



#-----#                   ~~Import things I am using~~                   #-----#

#         |
#        |
#       \/

import time
import itertools



#-----#        ~~Variables that I am using, including the list.~~        #-----#

#         |
#        |
#       \/

List = []
NumberOfXItems = []

#-----#                   ~~Functions that I am using.~~                 #-----#

#         |
#        |
#       \/

def HMNs():
    global TheStr, user_inputHMNs, List_input, List
    user_inputHMNs = input("You picked string. This program cannot calculate the mean or median, but it can calculate the mode. :D  How many strings are you using in your list? (Can not be a decimal number)  \nEnter:  ")
    user_inputHMNs
    time.sleep(1.5)
    TheStr = int(user_inputHMNs)
    for i in range(TheStr):
        List_input = input("Enter your strings. (One in each input field):  ")
        List.append(List_input)
        print("Your list -> ", List)
        if List.count == int(user_inputHMNs):
            break
        print("\n*Mode*:", mode())
        print("*Median*:",  "<Coming soon!>\n")
        print("*Mean*:",    mean())

def HMNn():
    global TheNum, user_inputHMNn, List_input, List
    user_inputHMNn = input("You picked number. :D How many numbers are you using in your list? (Can not be a decimal number) \nEnter:  ")
    user_inputHMNn
    time.sleep(1.5)
    TheNum = int(user_inputHMNn)
    for i in range(TheNum):
        List_input = input("Enter your numbers. (One in each input field):  ")
        List_input = int(List_input)
        List.append(List_input)
        print("\nYour list -> ", List)
        if List.count == int(user_inputHMNn):
            break
        print("\n*Mode*:", mode())
        print("*Median*:",  "<Coming soon!>")
        print("*Mean*:",    mean())

def NOS():
    while True: # Loops forever (until the break)
        answer = input("Does your list contain a number or a string?  \nEnter: ")
        answer = answer.lower()
        if answer in ("string", "str", "s"):
            HMNs()
            break
        elif answer in ("number", "num", "n", "int"):
            HMNn()
            break
        elif answer in ("quit", "q"):
            break  # Exits the while loop
        else:
            print("You did not enter a valid field, :P Sorry.  \nEnter: ")
    time.sleep(1.5)

def mean():
    thesum = sum(List)
    amount = len(List)
    themean = thesum / amount
    return themean

def mode():
    max_occurrences = 0
    themode = None
    for i in List:
        thecount = List.count(i)
        if thecount > max_occurrences:
            max_occurrences = thecount
            themode = i
    return themode



#-----#               ~~The functions which need calling~~               #-----#

#         |
#        |
#       \/

NOS()

[toc] | [prev] | [next] | [standalone]


#54331

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-09-17 17:02 -0400
Message-ID<mailman.89.1379451740.18130.python-list@python.org>
In reply to#54330

[Multipart message — attachments visible in raw view] — view raw

On Tue, Sep 17, 2013 at 4:10 PM, William Bryant <gogobebe2@gmail.com> wrote:

> Ok I think I've fixed it thanks I read everything.
>
>
> '''**************************************************************************'''
> #* Name:        Mode-Median-Mean Calculator
>     *#
> #*
>    *#
> #* Purpose:     To calculate the mode, median and mean of a list of
> numbers   *#
> #*              and the mode of a list of strings because that is what we
> are *#
> #*              learning in math atm in school :P
>     *#
> #*
>    *#
> #* Author:      William Bryant
>    *#
> #*
>    *#
> #* Created:     11/09/2013
>    *#
> #*
>    *#
> #* Copyright:   (c) William 2013
>    *#
> #*
>    *#
> #* Licence:     IDK :3
>    *#
>
> '''**************************************************************************'''
>
> The above comments are a mess.  In python, use docstrings -- put 3 quotes
> in front of all the documentation, and 3 at the end like:
> """
>
    Name:        Mode-Median-Mean Calculator
    Purpose:     To calculate the mode, median and mean of a list of
numbers   *#
    """

There is a utility called pydoc that will pull all docstrings from a module
and produce nice documentation.  So better to learn this style early

#-----#                   ~~Import things I am using~~
#-----#

#         |
#        |
#       \/

import time
import itertools

I don't think you use itertools, so remove the reference

#-----#        ~~Variables that I am using, including the list.~~
 #-----#

#         |
#        |
#       \/

List = []
NumberOfXItems = []

Using global variables is a very bad idea.  Since you seem to be a novice,
I'm wondering where you even learned about global variables.  If your
instructor taught you, then (s)he should look for a new line of work.
Using globals promotes lazy thought, makes debugging impossible in any
reasonably large piece of code.  Google about that.  Its important


#-----#                   ~~Functions that I am using.~~
> #-----#
>
> #         |
> #        |
> #       \/
>
> Use better names.  What does HMNs mean?  This function asks the user to
input a list of strings or numbers.  It is almost identical to HMNn to that
point that they should be combined most likely.


> def HMNs():
>
      """
      Here you should write about the function -- what it does, what is
needs passed to it, and what it returns.
      """




>     global TheStr, user_inputHMNs, List_input, List
>     user_inputHMNs = input("You picked string. This program cannot
> calculate the mean or median, but it can calculate the mode. :D  How many
> strings are you using in your list? (Can not be a decimal number)  \nEnter:
>  ")
>     user_inputHMNs
>     time.sleep(1.5)
>     TheStr = int(user_inputHMNs)
>     for i in range(TheStr):
>         List_input = input("Enter your strings. (One in each input field):
>  ")
>         List.append(List_input)
>         print("Your list -> ", List)
>         if List.count == int(user_inputHMNs):
>             break
>         print("\n*Mode*:", mode())
>         print("*Median*:",  "<Coming soon!>\n")
>         print("*Mean*:",    mean())
>
> def HMNn():
>     global TheNum, user_inputHMNn, List_input, List
>     user_inputHMNn = input("You picked number. :D How many numbers are you
> using in your list? (Can not be a decimal number) \nEnter:  ")
>     user_inputHMNn
>     time.sleep(1.5)
>     TheNum = int(user_inputHMNn)
>     for i in range(TheNum):
>         List_input = input("Enter your numbers. (One in each input field):
>  ")
>         List_input = int(List_input)
>         List.append(List_input)
>         print("\nYour list -> ", List)
>         if List.count == int(user_inputHMNn):
>             break
>         print("\n*Mode*:", mode())
>         print("*Median*:",  "<Coming soon!>")
>         print("*Mean*:",    mean())
>
> def NOS():
>     while True: # Loops forever (until the break)
>         answer = input("Does your list contain a number or a string?
>  \nEnter: ")
>         answer = answer.lower()
>         if answer in ("string", "str", "s"):
>             HMNs()
>             break
>         elif answer in ("number", "num", "n", "int"):
>             HMNn()
>             break
>         elif answer in ("quit", "q"):
>             break  # Exits the while loop
>         else:
>             print("You did not enter a valid field, :P Sorry.  \nEnter: ")
>     time.sleep(1.5)
>
> def mean():
>     thesum = sum(List)
>     amount = len(List)
>     themean = thesum / amount
>     return themean
>
> def mode():
>     max_occurrences = 0
>     themode = None
>     for i in List:
>         thecount = List.count(i)
>         if thecount > max_occurrences:
>             max_occurrences = thecount
>             themode = i
>     return themode
>
>
>
> #-----#               ~~The functions which need calling~~
> #-----#
>
> #         |
> #        |
> #       \/
>
> NOS()
>


So, I just added a few criticisms earlier above.  To sumarize:
   avoid global variables, document functions with docstrings, use really
clear names for variables including function  names.  If you have code in
two functions that is almost identical, figure out how to make them one
function

good luck

> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#54332

FromMRAB <python@mrabarnett.plus.com>
Date2013-09-17 22:26 +0100
Message-ID<mailman.90.1379453218.18130.python-list@python.org>
In reply to#54330
On 17/09/2013 21:10, William Bryant wrote:
> Ok I think I've fixed it thanks I read everything.
>
[snip]
>
> def HMNs():
>      global TheStr, user_inputHMNs, List_input, List
>      user_inputHMNs = input("You picked string. This program cannot calculate the mean or median, but it can calculate the mode. :D  How many strings are you using in your list? (Can not be a decimal number)  \nEnter:  ")

This line doesn't do anything:

>      user_inputHMNs
>      time.sleep(1.5)
>      TheStr = int(user_inputHMNs)
>      for i in range(TheStr):
>          List_input = input("Enter your strings. (One in each input field):  ")
>          List.append(List_input)
>          print("Your list -> ", List)

List.count is a method; it will never equal an integer:

>          if List.count == int(user_inputHMNs):
>              break
>          print("\n*Mode*:", mode())
>          print("*Median*:",  "<Coming soon!>\n")
>          print("*Mean*:",    mean())
>
> def HMNn():
>      global TheNum, user_inputHMNn, List_input, List
>      user_inputHMNn = input("You picked number. :D How many numbers are you using in your list? (Can not be a decimal number) \nEnter:  ")

This line doesn't do anything:

>      user_inputHMNn
>      time.sleep(1.5)
>      TheNum = int(user_inputHMNn)
>      for i in range(TheNum):
>          List_input = input("Enter your numbers. (One in each input field):  ")
>          List_input = int(List_input)
>          List.append(List_input)
>          print("\nYour list -> ", List)

List.count is a method; it will never equal an integer:

>          if List.count == int(user_inputHMNn):
>              break
>          print("\n*Mode*:", mode())
>          print("*Median*:",  "<Coming soon!>")
>          print("*Mean*:",    mean())
>
[snip]

[toc] | [prev] | [next] | [standalone]


#54333

FromWilliam Bryant <gogobebe2@gmail.com>
Date2013-09-17 14:31 -0700
Message-ID<2d53c19d-d923-4533-890a-af4aaf8ca794@googlegroups.com>
In reply to#54332
Thanks to all and @Joel Goldstick, I am learning python through youtube. They explained Global and Local variables to me. :) Thanks for that critisism, it really helps. I am 13 years old and I am looking forward to studing programming in University! :DDDDDD

[toc] | [prev] | [next] | [standalone]


#54340

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-09-17 19:49 -0400
Message-ID<mailman.95.1379461746.18130.python-list@python.org>
In reply to#54333

[Multipart message — attachments visible in raw view] — view raw

On Tue, Sep 17, 2013 at 5:31 PM, William Bryant <gogobebe2@gmail.com> wrote:

> Thanks to all and @Joel Goldstick, I am learning python through youtube.
> They explained Global and Local variables to me. :) Thanks for that
> critisism, it really helps. I am 13 years old and I am looking forward to
> studing programming in University! :DDDDDD
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Well, learn away.  Try the python.org tutorial too.  The best way to learn
( I think!) is to find all the tutorials you can and work through those
that suit you.  Look at python.org for pages that list many help sites,
including those for beginners.  Also, there is a python-tutor mailing
list/newsgroup that may be better for you at your stage of learning.  Keep
coming back when you get stuck

-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#54345

FromBryan Britten <britten.bryan@gmail.com>
Date2013-09-17 18:53 -0700
Message-ID<58bf80a9-86b3-4f00-b5ac-c460c88203f5@googlegroups.com>
In reply to#54252
William -

I'm also self-teaching myself Python and get stuck quite often, so I understand both the thrill of programming and the frustration. Given your young age and presumably very little exposure to other programming languages, I would highly recommend you check out http://www.Codecademy.com and work through their Python tutorials. It will teach you about the different object types (lists, dicts, tuples, etc) and about things like functions, methods and classes. I think you'll have a MUCH better understanding of Python that will allow you to choose which YouTube videos to watch much more wisely.

Good luck with your endeavors!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web