Error and Exception Handling · 11 / 20 Exercise Easy

Safe integer

Objective

Create a Python program that reads a text and converts it into an integer without the program crashing if it is not one.

Instructions

  • Read a text with input().
  • Try to convert it to an integer with int() inside a try block.
  • If it works, show double the number.
  • If it does not, catch ValueError and show Invalid number.
Input
21
Output
42

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

Start exercise