Fix: add exception handling to calculate function

This commit is contained in:
dev1-demo-agent
2026-08-29 16:30:26 +00:00
parent 3a7e249e09
commit eb3f57aba0
+3
View File
@@ -1,4 +1,5 @@
def calculate(a, b, op): def calculate(a, b, op):
try:
if op == '+': if op == '+':
return a + b return a + b
elif op == '-': elif op == '-':
@@ -11,6 +12,8 @@ def calculate(a, b, op):
return a / b return a / b
else: else:
return "Ошибка: неизвестная операция" return "Ошибка: неизвестная операция"
except Exception as e:
return f"Ошибка: {e}"
while True: while True:
expr = input("Введите выражение (или 'quit' для выхода): ") expr = input("Введите выражение (или 'quit' для выхода): ")