Complete the code to initialize a short-term memory buffer as an empty list.
short_term_memory = [1]The short-term memory buffer should start as an empty list to store conversation context.
Complete the code to add a new user message to the short-term memory list.
short_term_memory.[1](user_message)insert without specifying an index.remove or pop which delete items instead of adding.Use append to add a new message to the end of the list, preserving order.
Fix the error in the code to retrieve the last message from short-term memory safely.
last_message = short_term_memory[1] if short_term_memory else None
Using [-1] gets the last item in the list safely if the list is not empty.
Fill both blanks to create a function that clears short-term memory and returns its previous content.
def reset_memory(): previous = short_term_memory[1] short_term_memory[2]() return previous
copy() which returns a copy but is not used here.pop() which removes only one item.Use [:] to copy the list and clear() to empty it.
Fill all three blanks to update short-term memory by keeping only the last 5 messages.
short_term_memory = short_term_memory[1][-[2]:] if len(short_term_memory) > [3]: short_term_memory.pop(0)
Copy the list, keep last 5 messages, and remove oldest if more than 5.