Error and Exception Handling · 16 / 20 Exercise Medium

Calculator with finally

Objective

Create a Python program that divides two numbers and always shows a final message, whether or not there is an error.

Instructions

  • Read two integers, a and b.
  • Inside try, calculate a / b.
  • If ZeroDivisionError occurs, show Cannot divide by zero.
  • If there is no error (else block), show Result: R with the result to two decimals.
  • In the finally block, always show End of calculation.
Input
10
2
Output
Result: 5.00
End of calculation

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

Start exercise