human
Position of the K | Function that returns the Kth set bit.
Traverse in the binary.
Check if the last bit is set or not.
Check if count is equal to k then return the index.
Increase the index as we move right.
Right shift the number by 1.
Driver Code"
How can the above be solved in Python?
 Give me a code to position of the K and the other steps required?
assistant
#Here is code to position of the K and the other steps required.
 def FindIndexKthBit ( n , k ) :
	cnt , ind = 0 , 0
	while n > 0 :
		if n & 1 :
			cnt += 1
		if cnt == k :
			return ind
		ind += 1
		n = n >> 1
	return - 1
if __name__ == " _ _ main _ _ " :
	n , k = 15 , 3
	ans = FindIndexKthBit ( n , k )
	if ans != - 1 :
		print ( ans )
	else :
		print ( " No ▁ k - th ▁ set ▁ bit " )