livepython.net

152. Python Program to Double a Number with try and except

Easytry and except

Overview

Your first try and except: catch a bad number instead of crashing.

Problem Statement

Read a whole number and print its double, like this for 21:

Double: 42

If the input is not a whole number (like abc or 2.5), don't crash. Print:

That is not a whole number

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

One value. Example:

21

Output

The output for that example:

Double: 42

The tests try 4 different inputs.

Learn this firstChapter 17 · Python try except: Catch Errors Without Crashing
solution.py
# write your code here

EXPECTED OUTPUT

1Double: 42

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.