<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def weighted_variance (x, weights):
 """Return the variance of a weighted sample. The weighted sample mean is calculated and subtracted off, so the returned variance is upweighted by ``n / (n - 1)``. If the sample mean is known to be zero, you should just compute ``np.average (x**2, weights=weights)``. """

    n = len (x)
    if n < 3:
        raise ValueError ('cannot calculate meaningful variance of fewer '
                          'than three samples')
    wt_mean = np.average (x, weights=weights)
    return np.average (np.square (x - wt_mean), weights=weights) * n / (n - 1)