If you have $M$ marked element, then the number of iterations should be
$$\frac{\pi}{4}\sqrt{\frac{N}{M}} \text{where},\;\;\; N = 2^n $$
So, you need to replace this line
iterations = np.pi/4*np.sqrt(2**n)
with
iterations = np.pi/4*np.sqrt(2**n / 3)
Note also that, you should use floor()
instead of round()
to specify the number of iterations. Check out this answer for the details.