import math
import random


def pi(n=100):
    """
    Approximate pi using stochastic method with n iterations.

    Parameters
    ----------
    n : int, Optional, default: 100
        Number or iterations in stochastic method; must be >= 0

    Returns
    -------
    sum : float
        Resulting approximation of pi
    """

    count = 0
    for i in range(n):
        if math.sqrt(random.random()**2 + random.random()**2) < 1:
            count += 1
    ratio = count / n  # ratio of in circle to outside circle
    pi = ratio * 4
    return (pi)