← Lesson
Classes
Joeven
Run
Reset
Python loads on first run
class Agent: def __init__(self, goal): self.goal = goal self.step = 0 self.log = [] def run(self, max_steps): while self.step < max_steps: self.step += 1 row = {"step": self.step, "goal": self.goal} self.log.append(row) return self.log agent = Agent("find a file") print(agent.run(3)) print("step now", agent.step) other = Agent("write a note") print("other starts at", other.step, "log", other.log) print("same log object?", agent.log is other.log) def done(step, max_steps): return step >= max_steps print("done?", done(agent.step, 3)) print("run again continues", agent.run(4)[-1])
Run to execute this in your browser. Nothing is sent to a server.