#!/usr/bin/env python3 import random, math inside = 0 total = 10000000 for i in range(0, total): x = random.random() y = random.random() if math.sqrt(x**2 + y**2) < 1.0: # will also work: # if x**2 + y**2 < 1.0: inside += 1 area = float(inside) / total*(2**2) print("area of square", 2**2) print("area of circle", area)