Answer to Question #316817 in Python for MEDIAN1

Question #316817

Median

given a list of integers,write a program to print the median. 

input 

the input will be a single line of containing space-separated integers.

output

the second line of output should contain the median, round off the value to 2 decimal places.

median should be a float value when there are even number of elements, otherwise should be an integer value.

see sample input/output for the output format

explanation 

for example, if the given list of integers are 

2 4 5 6 7 8 2 4 5 2 3 8

the average of all the numbers is 4.67.

after sorting the array,

2 2 2 3 4 4 5 6 7 8 8

as the length of the list is an even number, the median will be the average of the two middle numbers in the sorted list.

the middle numbers will be 5 and 4. so the average of 5 and 4 will be median, which is 4.5

so the output should be

Median: 4.5


sample input 1

2 4 5 6 7 8 2 4 5 2 3 8

sample output 1

Median: 4.5


1
Expert's answer
2022-03-25T16:24:03-0400
import statistics
a = ( 2, 4, 5, 6, 7, 8, 2, 4, 5, 2, 3, 8)
print(statistics.median(a))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS