code: def spec_dice(spec):
      
      if spec[0] == 'c': 
          return str(spec[1])
      elif spec[0] == 'r':
          r = spec[1:]
          s = "{}d{}".format(r[0], r[1])
          if len(r) == 4 and ((r[2] == 'd' and r[3] < r[0]) or (r[2] == 'k' and r[3] > 0)):
              s += "{}{}".format(r[2], r[3])
          return s
      elif spec[0] in ops:
          return "{} {} {}".format(spec_dice(spec[1]), spec[0], spec_dice(spec[2]))
      else: raise ValueError("Invalid dice specification")
docs: Return the dice specification as a string in a common format