← Lesson
If, Elif, and Else
Joeven
Run
Reset
Python loads on first run
def next_action(obs): if obs.get("error"): return "retry" if obs.get("done"): return "stop" if obs.get("needs_tool"): return "call_tool" return "think" print("tool:", next_action({"needs_tool": True})) print("error:", next_action({"error": "timeout"})) print("done:", next_action({"done": True})) print("idle:", next_action({})) print("error wins:", next_action({"error": "timeout", "done": True})) ALLOWED = {"search", "read"} def gated(name): if name not in ALLOWED: return "reject" return "run" print("search:", gated("search")) print("shell:", gated("shell")) def handle_query(text): if not text: return "empty" if not text.strip(): return "empty" return "ok" print("blank quotes:", handle_query("")) print("only spaces:", handle_query(" ")) print("real text:", handle_query("weather")) result = {"ok": False, "error": "timeout"} print("dict is truthy?", bool(result)) print("ok field?", bool(result.get("ok")))
Run to execute this in your browser. Nothing is sent to a server.