def num_with_name(p,name):
    """
    Returns the number of people with name as a first name.

    This function does not just check ancestors; it checks
    p as well.

    Parameter p: The initial family member
    Precondition: p is a Person (and not None).

    Parameter name: The name to match
    Precondition: name is a string
    """
    # Check we match
    match = 1 if p.fname == name else 0
    
    # Work on small data    (BASE CASE)
    if p.mom == None and p.dad == None:
        # Conditional expression
        return match
    
    # Break up into halves  (RECURSIVE CASE)
    moms = 0
    if not p.mom == None:
        # No need to check mom; handled in recursive call.
        moms = num_with_name(p.mom,name)
    
    dads = 0
    if not p.dad == None:
        # No need to check dad; handled in recursive call.
        dads = num_with_name(p.dad,name)
    
    # Combine the answer
    return moms+dads+match