LearnPy Hub
← Exceptions problems
Hard

Calculator With Clear Errors

Read lines a op b until END. Define class CalcError(Exception) and raise it with a message for: a wrong number of parts (bad format), an unknown operator (unknown operator OP), a value that isn't a number (not a number: X) and division by zero (division by zero). Print each result with :g or error: MESSAGE, then ok=N errors=M.

Input

Lines, then END.

Output

Lines.

Sample 1

Input
3 + 4
10 / 0
2 ^ 3
x * 2
1 2
END
Output
7
error: division by zero
error: unknown operator ^
error: not a number: x
error: bad format
ok=1 errors=4

Sample 2

Input
5 * 5
END
Output
25
ok=1 errors=0
solution.py
Output appears here
Calculator With Clear Errors · Python practice problem · LearnPy Hub