human
Can you provide a code to average of a stream of numbers and the other steps required given the following:
Average of a stream of numbers | Returns the new average after including x.
Prints average of a stream of numbers.
Driver Code"
Solution in Python:
assistant
#Here is code to average of a stream of numbers and the other steps required.
 def getAvg ( x , n , sum ) :
	sum = sum + x ;
	return float ( sum ) / n ;
def streamAvg ( arr , n ) :
	avg = 0 ;
	sum = 0 ;
	for i in range ( n ) :
		avg = getAvg ( arr [ i ] , i + 1 , sum ) ;
		sum = avg * ( i + 1 ) ;
		print ( " Average ▁ of ▁ " , end = " " ) ;
		print ( i + 1 , end = " " ) ;
		print ( " ▁ numbers ▁ is ▁ " , end = " " ) ;
		print ( avg ) ;
	return ;
arr = [ 10 , 20 , 30 , 40 , 50 , 60 ] ;
n = len ( arr ) ;
streamAvg ( arr , n ) ;