def f_score(r: float, p: float, b: int = 1):
    """
    Calculate f-measure from recall and precision.

    Args:
        r: recall score
        p: precision score
        b: weight of precision in harmonic mean

    Returns:
        val: value of f-measure
    """
    try:
        val = (1 + b ** 2) * (p * r) / (b ** 2 * p + r)
    except ZeroDivisionError:
        val = 0
    return val