How Many Tries Did It Take?

Python for AIMedium+10 XP+10

How Many Tries Did It Take?

An app keeps asking for your age until it gets a good answer. A good answer is a whole number from 0 to 120, both included.

Here the replies come in as a list instead of from input(). Write attempts_needed(replies) that returns a list of two things:

  • how many replies were used, up to and including the first good one
  • that good age, as a whole number

If no reply is good, return [-1, -1].

Examples

replies = ["twenty", "-4", "31", "40"]
returns [3, 31]
replies = ["25"]
returns [1, 25]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run