Loading...
Loading...
A form asks for a positive whole number and allows several tries. The first line is the count m of tries. The next m lines are the tries.
Go through the tries in order. Stop at the first valid positive whole number and print Accepted <number> after <k> attempts. If none is valid, print No valid input after <m> attempts. Always print the word attempts.
Example 1
Input
3 abc -4 25
Output
Accepted 25 after 3 attempts
The third try is the first valid one.
Example 2
Input
2 x 0
Output
No valid input after 2 attempts
Nothing valid.
Try the problem first. Open one hint at a time.
Count the attempts in the loop. A number that is not positive can be rejected by raising ValueError yourself.
Use else on the try with break, and the for loop else for the no-valid-input message.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor