human
Program for Mean and median of an unsorted array | Function for calculating mean.
Function for calculating median.
First we sort the array.
check for even case.
Driver code.
Function call"
How can the above be solved in Python?
 What is a code to program for Mean and median of an unsorted array and the other steps required?
assistant
#Here is code to program for Mean and median of an unsorted array and the other steps required.
 def findMean ( a , n ) :
	sum = 0
	for i in range ( 0 , n ) :
		sum += a [ i ]
	return float ( sum / n )
def findMedian ( a , n ) :
	sorted ( a )
	if n % 2 != 0 :
		return float ( a [ int ( n / 2 ) ] )
	return float ( ( a [ int ( ( n - 1 ) / 2 ) ] + a [ int ( n / 2 ) ] ) / 2.0 )
a = [ 1 , 3 , 4 , 2 , 7 , 5 , 8 , 6 ]
n = len ( a )
print ( " Mean ▁ = " , findMean ( a , n ) )
print ( " Median ▁ = " , findMedian ( a , n ) )