code: def term_with_coeff(term, coeff):
      
      if not isinstance(coeff, Number):
          raise ValueError("coeff must be a Number")
      new_pauli = term.copy()
      # We cast to a complex number to ensure that internally the coefficients remain compatible.
      new_pauli.coefficient = complex(coeff)
      return new_pauli
docs: Change the coefficient of a PauliTerm.
  
      :param PauliTerm term: A PauliTerm object
      :param Number coeff: The coefficient to set on the PauliTerm
      :returns: A new PauliTerm that duplicates term but sets coeff
      :rtype: PauliTerm