Loading...
Loading...
A calculator reads one line with three words: a number, an operator (+, -, * or /) and a number. Print the result.
For +, - and * print a whole number. For / print the result with 2 decimal places. If a number is invalid print Invalid number. If the divisor is 0 print Cannot divide by zero. If the operator is not one of the four print Unknown operator.
<a> <op> <b>.Example 1
Input
8 * 5
Output
40
Multiplication.
Example 2
Input
9 / 0
Output
Cannot divide by zero
Divide by zero.
Try the problem first. Open one hint at a time.
Convert both numbers inside try and catch ValueError. Choose the operation with if and elif.
Dividing by zero raises ZeroDivisionError. An unknown operator is not a Python error, so use else for it.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor