PY-8

Find the First Acceptable Value

  • Easy
  • Loops and Sequences
  • Python

Task

Write find_first_acceptable(values, lower, upper). Read the numbers in values from left to right and find the first number in the inclusive interval from lower through upper.

Return a three-item tuple:

(value, index, found)
  • value is the first acceptable number.
  • index is its zero-based position in values.
  • found is True when an acceptable number exists and False otherwise.

When no value is acceptable, return (None, None, False). The input list must not be changed. The lower and upper boundaries are both included.

Example

The 12 is outside the interval, so the first acceptable value is 7 at index 2. A value equal to either boundary is acceptable:

Your implementation

Edit solution.py and keep this function name and signature:

values is a list of numbers and lower and upper are numbers. Return the required tuple; do not print it or ask for input.