python - How to find the median? -


i trying create function can number of inputs , find median. feel going wrong, cannot functional.
need do?

  1. i made list
  2. i asked user inputs
  3. i sorted numpy
  4. i printed median

code:

import numpy  numbers = [1,2,3]                 1 = input("please type first number")             2 = input("please type second number")        3 = input("please type third number")        median = numpy.median(numbers)             print(median)  

what trying accomplish:

what numbers find median for? 1,2,3,4,5,6,7
median is: 4

you should store numbers in list, , use loop add numbers it.

import numpy  size = int(input("enter number of numbers enter")) numbers = [] in range(size):     numbers.append(int(input("please type in number %d" % i)))  median = numpy.median(numbers)    print(median)  

your approach fails because try use numbers variable names, not valid.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -