LearnPy Hub
← Decorators problems
Hard

Retry Decorator

Write retry(times) that re-runs a function when it raises ValueError, up to times attempts, then returns 'failed'. A function reads the next input line and converts it to int. Read times first.

Input

times, then lines to try.

Output

The number or failed.

Sample 1

Input
3
x
y
42
Output
42

Sample 2

Input
2
x
y
42
Output
failed
solution.py
Output appears here
Retry Decorator · Python practice problem · LearnPy Hub