Function For Average Of A List Helppppp!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MDVking
    New Member
    • Oct 2008
    • 2

    Function For Average Of A List Helppppp!!

    hello im very new in python and i want to write a function that will return the sum of all the integer in a list
    how do i do that?
    someone please help me
    thank you
  • MDVking
    New Member
    • Oct 2008
    • 2

    #2
    Function For Average Of A List Helppppp!!

    hi im a beginner in python and im trying to write a function that calculates the average of a list of integers

    for ex:
    Code:
    L = [1,2,3,4,5]
    i want to return 1+2+3+4+5 which will give me 15

    can anyone help me pleaseee??
    Last edited by numberwhun; Oct 27 '08, 12:49 PM. Reason: Please use code tags

    Comment

    • Laharl
      Recognized Expert Contributor
      • Sep 2007
      • 849

      #3
      Where are you running into trouble? We're not going to write your code for you, but we will help with specific questions about code you've written yourself.

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        Look into loops. This is very basic stuff, and you have to show some initiative if you want any help. I'd have to guess you are a student and this is homework, and we have strict policies on how we can deal with homework questions.

        Also, what you are asking for is a sum, not an average.

        Comment

        • bvdet
          Recognized Expert Specialist
          • Oct 2006
          • 2851

          #5
          Python builtin function sum() will return the sum of the numbers in a list. The average is then calculated by dividing the sum by the length of the list. Hint: Python builtin function len() will be useful.

          Comment

          • boxfish
            Recognized Expert Contributor
            • Mar 2008
            • 469

            #6
            The function should take the list as an argument.
            You should make a variable to store the total number in.
            You should loop through the list with a for loop.
            For each number, add it to the total number.
            Return the total number.
            I hope this gives you some idea of what to do. Good luck.
            P.S.
            This doesn't seem to have much to do with the original thread. I am hoping a nice moderator will come by and give this its own thread. Thank you, moderators.

            Comment

            • Curtis Rutland
              Recognized Expert Specialist
              • Apr 2008
              • 3264

              #7
              Please don't post your questions in other threads. That is called thread hijacking and is not allowed. I have split out your posts and merged them with this thread.

              MODERATOR

              Comment

              Working...