code: def scale_degree_to_semitone(scale_degree):
      r
      semitone = 0
      offset = 0
      if scale_degree.startswith("#"):
          offset = scale_degree.count("#")
          scale_degree = scale_degree.strip("#")
      elif scale_degree.startswith('b'):
          offset = -1 * scale_degree.count("b")
          scale_degree = scale_degree.strip("b")
  
      semitone = SCALE_DEGREES.get(scale_degree, None)
      if semitone is None:
          raise InvalidChordException(
              "Scale degree improperly formed: {}, expected one of {}."
              .format(scale_degree, list(SCALE_DEGREES.keys())))
      return semitone + offset
docs: r"""Convert a scale degree to semitone.
  
      Parameters
      ----------
      scale degree : str
          Spelling of a relative scale degree, e.g. 'b3', '7', '#5'
  
      Returns
      -------
      semitone : int
          Relative semitone of the scale degree, wrapped to a single octave
  
      Raises
      ------
      InvalidChordException if `scale_degree` is invalid.