code: def pauli_expectation(self, prep_prog, pauli_terms):
          
  
          is_pauli_sum = False
          if isinstance(pauli_terms, PauliSum):
              progs, coeffs = pauli_terms.get_programs()
              is_pauli_sum = True
          else:
              coeffs = [pt.coefficient for pt in pauli_terms]
              progs = [pt.program for pt in pauli_terms]
  
          bare_results = self.expectation(prep_prog, progs)
          results = [c * r for c, r in zip(coeffs, bare_results)]
          if is_pauli_sum:
              return sum(results)
          return results
docs: Calculate the expectation value of Pauli operators given a state prepared by prep_program.
  
          If ``pauli_terms`` is a ``PauliSum`` then the returned value is a single ``float``,
          otherwise the returned value is a list of ``float``s, one for each ``PauliTerm`` in the
          list.
  
          :note: If the execution of ``quil_program`` is **non-deterministic**, i.e., if it includes
              measurements and/or noisy quantum gates, then the final wavefunction from which the
              expectation values are computed itself only represents a stochastically generated
              sample. The expectations returned from *different* ``expectation`` calls *will then
              generally be different*.
  
          :param Program prep_prog: Quil program for state preparation.
          :param Sequence[PauliTerm]|PauliSum pauli_terms: A list of PauliTerms or a PauliSum.
          :return: If ``pauli_terms`` is a PauliSum return its expectation value. Otherwise return
            a list of expectation values.
          :rtype: float|List[float]