give me a code that retruns the median of a list. all elements of this list are the number zero in python

Since all elements of list are zero, the median will also be zero. You can calculate median using statistics module's median method.

Here is the code to return the median of the list:

main.py
import statistics

zero_list = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # List with 10 elements all with value 0.
median = statistics.median(zero_list)
print("Median: ", median) # Output: Median:  0
189 chars
6 lines

If the list contains an odd number of elements then the median will be the middle element. If the list contains an even number of elements then the median will be the average of the middle two elements.

related categories

gistlibby LogSnag