<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def count_genes(model):
 """Count the number of distinct genes in model reactions."""

    genes = set()
    for reaction in model.reactions:
        if reaction.genes is None:
            continue

        if isinstance(reaction.genes, boolean.Expression):
            genes.update(v.symbol for v in reaction.genes.variables)
        else:
            genes.update(reaction.genes)

    return len(genes)