def calc_f1_score(n_tp: int, n_fp: int, n_fn: int) -> float:
    """Calculate F1 score."""

    if (n_tp + n_fp) == 0 or (n_tp + n_fn) == 0:
        return 0

    precision = n_tp / (n_tp + n_fp)
    recall = n_tp / (n_tp + n_fn)

    if precision > 0 or recall > 0:
        f1 = (2 * precision * recall) / (precision + recall)
    else:
        f1 = 0
    return f1