Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to catch retrieval errors and return None.
Agentic AI
try: result = retrieve_data(query) except [1]: result = None
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Catching only specific errors like KeyError may miss other failures.
Not catching any error causes the program to crash on failure.
✗ Incorrect
Using Exception catches all errors during retrieval, allowing graceful failure.
2fill in blank
mediumComplete the code to retry retrieval up to 3 times on failure.
Agentic AI
for attempt in range(3): try: data = retrieve_data(query) break except [1]: continue
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a narrow exception may miss some errors and stop retries.
Not using try-except inside the loop causes crashes.
✗ Incorrect
Using Exception ensures all errors trigger a retry.
3fill in blank
hardFix the error in the retrieval fallback code to handle missing keys.
Agentic AI
try: value = data['key'] except [1]: value = default_value
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Catching the wrong error type causes the fallback to fail.
Not catching any error leads to program crash on missing keys.
✗ Incorrect
KeyError is raised when a dictionary key is missing, so catching it allows fallback.
4fill in blank
hardFill both blanks to log retrieval failure and return fallback data.
Agentic AI
try: result = retrieve_data(query) except [1] as e: logger.[2](f"Retrieval failed: {e}") result = fallback_data
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a narrow exception misses some errors.
Logging with wrong method name causes runtime errors.
✗ Incorrect
Catching Exception logs the error as a warning and returns fallback data.
5fill in blank
hardFill all three blanks to implement a safe retrieval with retry and fallback.
Agentic AI
for attempt in range(3): try: data = retrieve_data(query) break except [1]: logger.[2](f"Attempt {attempt + 1} failed.") else: data = [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong exception type causes missed retries.
Logging with wrong method name causes errors.
Not providing fallback data leads to undefined variables.
✗ Incorrect
This code retries retrieval catching all exceptions, logs warnings on failure, and uses fallback data if all attempts fail.