<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def doEpisodes(self, number=1):
 """ Do the given numer of episodes, and return the rewards of each step as a list. """

        for episode in range(number):
            print "Starting episode %d." % episode

            # Initialise the profile cycle.
            if len(self.profile.shape) == 1: # 1D array
                self._pcycle = cycle(self.profile)
            else:
                assert self.profile.shape[0] >= number
                self._pcycle = cycle(self.profile[episode, :])

            # Scale the initial load.
            c = self._pcycle.next()
            for bus in self.market.case.buses:
                bus.p_demand = self.pdemand[bus] * c

            # Initialise agents and their tasks.
            for task, agent in zip(self.tasks, self.agents):
                agent.newEpisode()
                task.reset()

            while False in [task.isFinished() for task in self.tasks]:
                if True in [task.isFinished() for task in self.tasks]:
                    raise ValueError
                self._oneInteraction()

        self.reset_case()