While Loop Input Validation Simulator

Medium ⏱ 12 min 48% acceptance ★★★★★ 4.5
Write a function first_valid_entry(attempts, minimum) that simulates validating a sequence of pre-supplied input attempts (a list of numbers) using a while loop with an index counter. Return the first value in attempts that is greater than or equal to minimum. If none qualify, return None.

Examples

Example 1
Input
first_valid_entry([2, 5, 9, 3], 5)
Output
5
Explanation

5 is the first value >= 5.

Example 2
Input
first_valid_entry([1, 2, 3], 10)
Output
None
Explanation

No value meets the minimum.

Constraints

  • attempts is a list of numbers.
  • Must use a while loop with a manually managed index.

Topics

Loopswhile loop

Companies

DeloitteCapgemini

Hints

Hint 1

Track an index `i = 0` and loop `while i < len(attempts):`.

Hint 2

Return as soon as you find a qualifying value; return None after the loop if nothing matched.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.