human
Solve in Python:
We need a system that can learn facts about family relationships, check their consistency and answer queries about them.

# The task

~~~if:javascript
Create a class `Family` with the following methods. All arguments are strings: names of persons. Upon the first use of a name, that name is added to the family.

* `male(name)` and `female(name)` returning `boolean`

 Define the gender (corresponding to the method name) of the given person. Return `false` when these assignments cannot be made because of conflicts with earlier registered information.
  
* `isMale(name)` and `isFemale(name)` returning `boolean`

 Return `true` when the person has the said gender. When no gender was assigned, both methods should return `false`
 
* `setParent(childName, parentName)` returning `boolean`

 Defines the child-parent relationship between two persons. Returns `false` when the relationship cannot be made because of conflicts with earlier registered information.

* `getParents(name)` and `getChildren(name)` returning `array` of `string`
 
 Return the names of the person's parents/children in alphabetical order
~~~
~~~if:python
Create a class `Family` with the following methods. All arguments are strings: names of persons. Upon the first use of a name, that name is added to the family.

* `male(name)` and `female(name)` returning `boolean`

 Define the gender (corresponding to the method name) of the given person. Return `False` when these assignments cannot be made because of conflicts with earlier registered information.
  
* `is_male(name)` and `is_female(name)` returning `boolean`

 Return `True` when the person has the said gender. When no gender was assigned, both methods should return `False`
 
* `set_parent_of(child_name, parent_name)` returning `boolean`

 Defines the child-parent relationship between two persons. Returns `False` when the relationship cannot be made because of conflicts with earlier registered information.

* `get_parents_of(name)` and `get_children_of(name)` returning `list` of `string`
 
 Return...
 What is a the Python code you requested?
assistant
#Here is the Python code you requested.

from collections import defaultdict

class family:
    def __init__(self):
        self.males = set()
        self.females = set()
        self.parents = defaultdict(lambda: set())
        self.children = defaultdict(lambda: set())
        
    def male(self, name):
        if name in self.females:
            return False
        if name in self.males:
            return True
        safe_copy = self.males.copy()
        self.males.add(name)
        for child in self.parents[name]:
            partners = self.children[child] - {name}
            for partner in partners:
                if not self.female(partner):
                    self.males = safe_copy
                    return False
        return True
    def is_male(self, name):
        return name in self.males
    def female(self, name):
        if name in self.males:
            return False
        if name in self.females:
            return True
        safe_copy = self.females.copy()
        self.females.add(name)
        for child in self.parents[name]:
            partners = self.children[child] - {name}
            for partner in partners:
                if not self.male(partner):
                    self.females = safe_copy
                    return False
        return True
    def is_female(self, name):
        return name in self.females
    def set_parent_of(self, child_name, parent_name):
        if child_name == parent_name:
            return False
        parents = self.children[parent_name]
        while parents:
            if child_name in parents:
                return False
            new_parents = set()
            for parent in parents:
                new_parents |= self.children[parent]
            parents = new_parents
        current_parents = self.children[child_name]
        if parent_name in current_parents:
            return True
        if len(current_parents) >= 2:
            return False
        new_parents = current_parents | {parent_name}
        if len(new_parents & self.males) > 1 or len(new_parents &...