title: Implementing a dictionary function to calculate the average of a list
body: <p>As always, I've attempted this for awhile before I proceed to ask a question on here. I know there are several attempts at answering this, but none really worked for what I needed.   </p>
  
  <p>Here are the instructions:</p>
  
  <p>Implement the following three functions (you should use an appropriate looping construct to compute the averages):</p>
  
  <pre><code>allNumAvg(numList) : takes a list of numbers and returns the average of all the numbers in the list.
  posNumAvg(numList) : takes a list of numbers and returns the average of all the numbers in the list that are greater than zero.
  nonPosAvg(numList) : takes a list of numbers and returns the average of all the numbers in the list that are less than or equal to zero.
  </code></pre>
  
  <p>Write a program that asks the user to enter some numbers (positives, negatives and zeros). Your program should NOT ask the user to enter a fixed number of numbers. Also it should NOT ask for the number of numbers the user wants to enter. But rather it should ask the user to enter a few numbers and end with -9999 (a sentinel value). The user can enter the numbers in any order. Your program should NOT ask the user to enter the positive and the negative numbers separately.</p>
  
  <p>Your program then should create a list with the numbers entered (make sure NOT to include the sentinel value (-9999) in this list) and output the list and a dictionary with the following Key-Value pairs (using the input list and the above functions):</p>
  
  <pre><code>Key = 'AvgPositive'  :  Value = the average of all the positive numbers
  Key = 'AvgNonPos'  :  Value = the average of all the non-positive numbers
  Key = 'AvgAllNum'  :  Value = the average of all the numbers
  </code></pre>
  
  <p>Sample run:</p>
  
  <p>Enter a number (-9999 to end):  4</p>
  
  <p>Enter a number (-9999 to end):  -3</p>
  
  <p>Enter a number (-9999 to end): -15</p>
  
  <p>Enter a number (-9999 to end):  0</p>
  
  <p>Enter a number (-9999 to end):  10</p>
  
  <p>Enter a number (-9999 to end):  22</p>
  
  <p>Enter a number (-9999 to end):  -9999</p>
  
  <p>The list of all numbers entered is:</p>
  
  <p>[4, -3, -15, 0, 10, 22]</p>
  
  <p>The dictionary with averages is:</p>
  
  <p>{'AvgPositive': 12.0, 'AvgNonPos': -6.0, 'AvgAllNum': 3.0}</p>
  
  <p>Here's is my code:</p>
  
  <pre><code>a = []
  b = []
  c = []
  dictionary = {}
  total = 0
  
  print("Enter positive, negative or zero to determine the average: ")
  while(True):
      user_input = int(input("Enter a number (-9999 to end): "))
      if(user_input == -9999):
          break
  
  def allNumAvg(values):
      for number in a:
          total = total + number
          average = sum(total) / len(total)
          if user_input &gt; 0 or user_input &lt; 0:
              a.append(user_input)
      return average
  
  
  def posNumAvg(values):
      for number in b:
          total = total + number
          average = sum(total) / len(total)
          if user_input &gt; 0:
              b.append(user_input)
      return average
  
  def nonPosAvg(values):
      for number in c:
          total = total + number
          average = sum(total) + len(total)
          if user_input &lt; 0:
              c.append(user_input)
      return average
  
  print("The list of all numbers entered is:")
  print(a+b+c)
  
  dictionary = {
      "AvgPositive": posNumAvg(values),
      "AvgNonPos": nonPosAvg(values),
      "AvgAllNum": allNumAvg(values)
  }
  
  
  
  print("The dictionary with the averages are:")
  print(dictionary) 
  </code></pre>
  
  <p>My question is how can I implement the averages to be printed from the dictionary since I'm currently getting the error of:    <code>"AvgPositive": posNumAvg(values), NameError: name 'values' is not defined</code>.  Additionally, how would I get the list of the numbers entered to print?</p>
  
  <p>Thanks!</p>