Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
2fill in blank
mediumComplete 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'
Attempts:
3 left
3fill in blank
hardFix 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'
Attempts:
3 left
4fill in blank
hardFill 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'
Attempts:
3 left
5fill in blank
hardFill 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'
Attempts:
3 left
