def get_ncells(nb):
    """Return number of code cells in a notebook."""
    ncells = 0
    for ws in nb.worksheets:
        for cell in ws.cells:
            if cell.cell_type == "code":
                ncells += 1
    return ncells