Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to save the agent's state to a file.
Agentic AI
with open('agent_state.pkl', [1]) as f: pickle.dump(agent_state, f)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' instead of 'wb' causes errors when saving binary data.
Using 'r' or 'rb' opens the file for reading, not writing.
✗ Incorrect
The agent's state is saved in binary mode, so 'wb' (write binary) is needed.
2fill in blank
mediumComplete the code to load the agent's state from a file.
Agentic AI
with open('agent_state.pkl', [1]) as f: agent_state = pickle.load(f)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'r' instead of 'rb' causes errors when loading binary data.
Using 'w' or 'wb' opens the file for writing, not reading.
✗ Incorrect
Loading pickled data requires reading in binary mode, so 'rb' is correct.
3fill in blank
hardFix the error in the code to correctly save the agent's state.
Agentic AI
pickle.dump(agent_state, open('state.pkl', [1]))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' causes errors because pickle needs binary mode.
Using 'r' or 'rb' is for reading, not writing.
✗ Incorrect
Saving with pickle requires opening the file in write binary mode 'wb'.
4fill in blank
hardFill both blanks to create a dictionary comprehension that saves only keys with values greater than 10.
Agentic AI
filtered_state = {k: v for k, v in agent_state.items() if v [1] 10 and isinstance(v, [2])} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '==' instead of '>' changes the filter condition.
Using wrong type in isinstance causes no filtering.
✗ Incorrect
We want values greater than 10 and to check if value is an int (using 'int').
5fill in blank
hardFill all three blanks to update the agent's state, save it, and then load it back.
Agentic AI
agent_state[[1]] = [2] with open('agent_state.pkl', [3]) as f: pickle.dump(agent_state, f) with open('agent_state.pkl', 'rb') as f: loaded_state = pickle.load(f)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong file mode causes errors when saving.
Using wrong key or value names breaks the update.
✗ Incorrect
We update the key 'last_action' with 'new_value', then save with 'wb' mode.