human
Expectation or expected value of an array | Function to calculate expectation.
variable prb is for probability of each element which is same for each element.
calculating expectation overall.
returning expectation as sum.
Driver program.
Function for calculating expectation.
Display expectation of given array"
How can the above be solved in Python?
assistant
#Here is code to expectation or expected value of an array and the other steps required.
 def calc_Expectation ( a , n ) :
	prb = 1 / n
	sum = 0
	for i in range ( 0 , n ) :
		sum += ( a [ i ] * prb )
	return float ( sum )
n = 6 ;
a = [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 ]
expect = calc_Expectation ( a , n )
print ( " Expectation ▁ of ▁ array ▁ E ( X ) ▁ is ▁ : ▁ " , expect )