<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _cnf_formula(lexer, varname, nvars, nclauses):
 """Return a DIMACS CNF formula."""

    clauses = _clauses(lexer, varname, nvars)

    if len(clauses) < nclauses:
        fstr = "formula has fewer than {} clauses"
        raise Error(fstr.format(nclauses))
    if len(clauses) > nclauses:
        fstr = "formula has more than {} clauses"
        raise Error(fstr.format(nclauses))

    return ('and', ) + clauses