human
Count triplets with sum smaller than a given value | A Simple Python 3 program to count triplets with sum smaller than a given value include < bits / stdc ++ . h >.
Initialize result.
Fix the first element as A [ i ].
Fix the second element as A [ j ].
Now look for the third number.
Driver program"
How can the above be solved in Python?
 Write me a code to count triplets with sum smaller than a given value and the other steps required?
assistant
#Here is code to count triplets with sum smaller than a given value and the other steps required.
 def countTriplets ( arr , n , sum ) :
	ans = 0
	for i in range ( 0 , n - 2 ) :
		for j in range ( i + 1 , n - 1 ) :
			for k in range ( j + 1 , n ) :
				if ( arr [ i ] + arr [ j ] + arr [ k ] < sum ) :
					ans += 1
	return ans
arr = [ 5 , 1 , 3 , 4 , 7 ]
n = len ( arr )
sum = 12
print ( countTriplets ( arr , n , sum ) )