Error and Exception Handling · 13 / 20 Exercise Medium

Retry until valid

Objective

Create a Python program that asks for an integer between 1 and 10 and keeps asking until the user types a valid one.

Instructions

  • Read a text on each attempt.
  • If it is not an integer or it is not between 1 and 10, show Try again and ask again.
  • When the value is valid, show You chose N, with the number in place of N.
  • Use a while loop and try/except to catch ValueError.
Input
5
Output
You chose 5

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise