<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_outcome(self, outcome):
 """Set the outcome of this work unit. We can set the outcome on a work unit directly, but that outcome will also be affected by those of its subunits. The right thing happens: The outcome of a work unit is the worst outcome of any of its subunits and any outcome set on it directly."""

    if outcome not in range(0, 5):
      raise Exception('Invalid outcome: {}'.format(outcome))

    if outcome < self._outcome:
      self._outcome = outcome
      if self.parent: self.parent.set_outcome(self._outcome)