Plumbing determines your sex, state of mind decides the rest.
Not exactly, since some hermaphrodites are born with both sets, some have a penis, but also ovaries and sometime even sort of a uterus.