human
Count of subarrays forming an Arithmetic Progression ( AP ) | Function to find the total count of subarrays.
Iterate over each subarray.
Difference between first two terms of subarray.
Iterate over the subarray from i to j.
Check if the difference of all adjacent elements is same.
Driver Code.
Given array.
Function call"
How can the above be solved in Python?
 ... Give me a code to count of subarrays forming an Arithmetic Progression ( AP ) and the other steps required?
assistant
#Here is code to count of subarrays forming an Arithmetic Progression ( AP ) and the other steps required.
 def calcSubarray ( A , N ) :
	count = 0
	for i in range ( N ) :
		for j in range ( i + 1 , N ) :
			flag = True
			comm_diff = A [ i + 1 ] - A [ i ]
			for k in range ( i , j ) :
				if ( A [ k + 1 ] - A [ k ] == comm_diff ) :
					continue
				else :
					flag = False
					break
			if ( flag ) :
				count += 1
	return count
if __name__ == ' _ _ main _ _ ' :
	A = [ 8 , 7 , 4 , 1 , 0 ]
	N = len ( A )
	print ( calcSubarray ( A , N ) )