Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to retry a function call once if it fails.
Agentic AI
try: result = perform_task() except Exception: result = [1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a fallback function instead of retrying the main task.
Not retrying the function at all.
✗ Incorrect
The code retries the same function 'perform_task' once after catching an exception.
2fill in blank
mediumComplete the code to fallback to an alternative function if the main task fails.
Agentic AI
try: result = main_task() except Exception: result = [1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Retrying the main task instead of falling back.
Logging error instead of handling fallback.
✗ Incorrect
On failure, the code falls back to 'alternative_task' as a backup.
3fill in blank
hardFix the error in the retry loop to stop after 3 attempts.
Agentic AI
attempts = 0 while attempts < 3: try: result = task() break except Exception: attempts [1] 1
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Decreasing the attempts counter causing infinite loop.
Using multiplication or division operators incorrectly.
✗ Incorrect
The attempts counter should increase by 1 each time to limit retries.
4fill in blank
hardFill both blanks to implement retry with fallback after 3 failed attempts.
Agentic AI
attempts = 0 while attempts < 3: try: result = [1]() break except Exception: attempts [2] 1 else: result = fallback()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using fallback function inside the retry loop.
Decreasing attempts counter causing infinite retries.
✗ Incorrect
The code retries 'main_task' increasing attempts by 1, then falls back after 3 failures.
5fill in blank
hardFill all three blanks to log errors, retry twice, then fallback.
Agentic AI
import logging attempts = 0 while attempts < [1]: try: result = [2]() break except Exception as e: logging.error(str(e)) attempts [3] 1 else: result = fallback()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting retry count to 1 causing only one attempt.
Not logging errors properly.
Using wrong operator to update attempts.
✗ Incorrect
The code retries 'main_task' twice, logs errors, increments attempts, then falls back.