human
Count of subarrays with average K | Function to count subarray having average exactly equal to K.
To Store the final answer.
Calculate all subarrays.
Calculate required average.
Check if average is equal to k.
Required average found.
Increment res.
Driver code.
Given Input.
Function Call"
How can the above be solved in Python?

What is a code to count of subarrays with average K and the other steps required?
assistant
#Here is code to count of subarrays with average K and the other steps required.
 def countKAverageSubarrays ( arr , n , k ) :
	res = 0
	for L in range ( n ) :
		sum = 0
		for R in range ( L , n , 1 ) :
			sum += arr [ R ]
			len1 = ( R - L + 1 )
			if ( sum % len1 == 0 ) :
				avg = sum // len1
				if ( avg == k ) :
					res += 1
	return res
if __name__ == ' _ _ main _ _ ' :
	K = 6
	arr = [ 12 , 5 , 3 , 10 , 4 , 8 , 10 , 12 , - 6 , - 1 ]
	N = len ( arr )
	print ( countKAverageSubarrays ( arr , N , K ) )