<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def expectation(self, prep_prog, operator_programs=None):
 """ Calculate the expectation value of operators given a state prepared by prep_program. :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*. To measure the expectation of a PauliSum, you probably want to do something like this:: progs, coefs = hamiltonian.get_programs() expect_coeffs = np.array(cxn.expectation(prep_program, operator_programs=progs)) return np.real_if_close(np.dot(coefs, expect_coeffs)) :param Program prep_prog: Quil program for state preparation. :param list operator_programs: A list of Programs, each specifying an operator whose expectation to compute. Default is a list containing only the empty Program. :return: Expectation values of the operators. :rtype: List[float] """

        # Developer note: This code is for backwards compatibility. It can't be replaced with
        # ForestConnection._expectation because we've turned off the ability to set
        # `needs_compilation` (that usually indicates the user is doing something iffy like
        # using a noise model with this function)

        if isinstance(operator_programs, Program):
            warnings.warn(
                "You have provided a Program rather than a list of Programs. The results from expectation "
                "will be line-wise expectation values of the operator_programs.", SyntaxWarning)

        payload = self._expectation_payload(prep_prog, operator_programs)
        response = post_json(self.session, self.sync_endpoint + "/qvm", payload)
        return response.json()