-2
def test(): # do not change this or the next line!
    numbers = [11.5, 28.3, 23.5, -4.8, 15.9, -63.1, 79.4, 80.0, 0, 67.4, -11.9, 32.6]
      average = 0

  # I need to write my code here so that it sets average
  # to the average of the non-negative numbers

     print(average)
  return average # do not change this line!
  # do not write any code below here  

    test()  # do not change this line!
# do not remove this line!
DYZ
  • 55,249
  • 10
  • 64
  • 93

1 Answers1

-1

Use numpy .

STEPS:

  • Find out the positive integers
  • take a mean of those.

import numpy as np
def test(): # do not change this or the next line!
    numbers = [11.5, 28.3, 23.5, -4.8, 15.9, -63.1, 79.4, 80.0, 0, 67.4, -11.9, 32.6]
    num = np.array(numbers)
    avg = np.mean((num[num >= 0]), axis=0)
    return avg # do not change this line!
  # do not write any code below here  

test() 

Output:

37.62222222222223

Edit:

def test(): # do not change this or the next line! 
    numbers = [11.5, 28.3, 23.5, -4.8, 15.9, -63.1, 79.4, 80.0, 0, 67.4, -11.9, 32.6] 
    num = [i for i in numbers if i>=0] 
    avg = sum(num)/len(num) 
    return avg # do not change this line! 
    # do not write any code below here   

test() 
Pygirl
  • 12,969
  • 5
  • 30
  • 43