Fix: add exception handling to calculate function
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
def calculate(a, b, op):
|
||||
try:
|
||||
if op == '+':
|
||||
return a + b
|
||||
elif op == '-':
|
||||
@@ -11,6 +12,8 @@ def calculate(a, b, op):
|
||||
return a / b
|
||||
else:
|
||||
return "Ошибка: неизвестная операция"
|
||||
except Exception as e:
|
||||
return f"Ошибка: {e}"
|
||||
|
||||
while True:
|
||||
expr = input("Введите выражение (или 'quit' для выхода): ")
|
||||
|
||||
Reference in New Issue
Block a user