Bird
Raised Fist0
Agentic AIml~10 mins

Caching and result reuse in Agentic AI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to store the result in cache after computation.

Agentic AI
cache['result'] = [1](data)
Drag options to blanks, or click blank then click option'
Aprocess_data
Bload_data
Cclear_cache
Dreset_data
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function that does not compute the result, like loading or clearing data.
2fill in blank
medium

Complete the code to check if the result is already cached before computing.

Agentic AI
if 'result' not in cache:
    cache['result'] = [1](input_data)
Drag options to blanks, or click blank then click option'
Areset_result
Bclear_cache
Cload_cache
Dcompute_result
Attempts:
3 left
💡 Hint
Common Mistakes
Calling functions that clear or reset cache instead of computing the result.
3fill in blank
hard

Fix the error in the code to reuse cached results properly.

Agentic AI
def get_result(data):
    if [1] in cache:
        return cache['result']
    cache['result'] = compute(data)
    return cache['result']
Drag options to blanks, or click blank then click option'
A'result'
Bresult
C'cache'
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for a variable instead of a string key in the dictionary.
4fill in blank
hard

Fill both blanks to create a cache dictionary that stores results only if input is new.

Agentic AI
def cached_compute(input):
    if input [1] cache:
        return cache[input]
    cache[input] = [2](input)
    return cache[input]
Drag options to blanks, or click blank then click option'
Anot in
Bin
Ccompute_result
Dclear_cache
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'in' instead of 'not in' causes recomputation to be skipped incorrectly.
Calling a function that clears cache instead of computing result.
5fill in blank
hard

Fill all three blanks to implement a caching mechanism with a function and cache dictionary.

Agentic AI
cache = {}

def [1](x):
    if x [2] cache:
        return cache[x]
    cache[x] = [3](x)
    return cache[x]
Drag options to blanks, or click blank then click option'
Aget_cached_result
Bnot in
Cexpensive_calculation
Dclear_cache
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'in' instead of 'not in' causes wrong caching behavior.
Using a function that clears cache instead of computing result.