import numpy as np n = 100000 r = 1 #radius of the circle inside = 0 for k in range (0, n): # Coordinates in first quadrant: [x_coor, y_coor] = np.random.random(2) dist = np.sqrt(x_coor**2 + y_coor**2) if (dist < r): inside = inside + 1 print('Pi is esitmated to be:', f'{ 4*inside/n :.4f}') # Inside is mult. by 4 as we only consider first quadrant