In the try block, you need to put not a check, but a piece of code in which we expect a potential problem. Verification is not needed at all - the mechanism for catching exceptions replaces them.
In addition, you have a confusion with when to throw an exception, and when to catch it. Read more, for which exceptions are generally needed.
Well, never in any case after the line starting with if can not be a line with a smaller indent.
You need something like this:
import operator OPER_MAP = { '+': operator.add, '-': operator.sub, '*': operator.mul, '/': operator.truediv, } def calculator(): s = input("Знак (+,-,*,/): ") if s not in OPER_MAP: raise ValueError() x = float(input("x=")) y = float(input("y=")) if s == '/' and y < 0: # Просто для примера. # На самом деле, такое исключение и так бы выбросилось # при попытке делить на ноль # и эту проверку можно вообще убрать raise ZeroDivisionError operation = OPER_MAP[s] print(operation(x, y)) while True: try: calculator() except ValueError: print("Такой арифметической операции не существует, попробуйте ещё раз") except ZeroDivisionError: print("Делить на ноль нельзя, попробуйте сначала")
(The code is designed for the third python. For the second, in particular, you need to truediv replace with div)