2. Flow Control, Retry Loops & Enumerate

Flow Control in Automation

# Evaluating status codes:
status_code = 200
if status_code == 200:
    print("API Success")
elif status_code == 404:
    print("Endpoint not found")
else:
    print(f"Unexpected status: {status_code}")

# Retry loop pattern:
max_retries = 3
for attempt in range(1, max_retries + 1):
print(f"Attempt {attempt} of {max_retries}")
# poll element state

Task

  • Implement find_index_of_target(items, target):
  • 1. Use enumerate(items) in a for loop.
  • 2. If item == target, return index.
  • 3. Return -1 if not found.
πŸ’‘Common doubts
Did you like the problem?
Lesson 2 of 37
Python
Loading code editor…
Next