If you read some of the formal methods books carefully, they suggest that you do this kind of thing.
Define the post-condition
isMale && doGuyStuff || isFemale && doGirlStuff.
Derive some candidate statements that will lead to this post condition
if isMale: doGuyStuff
That provably leads to some of the post-condition
if isFemale: doGirlStuff
That's provably leads to some of the post-condition
Note that order does not matter. Indeed, it's simpler if you remove any ordering assumptions.
You wind up with the following:
if isMale: doGuyStuff
elif isFemale: doGirlStuff
Note that there's no proper use for an else
clause. You'll never -- in a formal derivation -- derive an else
clause. You'll always have conditions that are positive statements: a && b || c && d
kinds of things. Rarely it will be a && b || !a && c
, but even then, you usually wind up with the explicit !a
condition.
Formally, the "impossible else" clause should be limited to doing something like the following.
if isMale: doGuyStuff
elif isFemale: doGirlStuff
else:
raise HorrifyingSituationError
Should you ever raise the HorrifyingSituationError, it means that you did the math wrong and improperly derived the statements from the conditions. Or you improperly defined the post-condition in the first place.
Either way, the program was designed wrong in a profound and absolute way. Generally, this is not a surprise. It usually fails spectacularly the first time you try to test it. Unless (as it often happens) you chose test data that reflects the errors in your original definition of the post-condition. Even then, once you encounter this exception, you can easily track it down and fix it permanently.