def Calculator(operator, *args): expression = f" {operator} ".join(map(str, args)) try: result = eval(expression) return int(result) except: return "Invalid expression. Please try again."
def Calculator(expression):- def Calculator(operator, *args):
- expression = f" {operator} ".join(map(str, args))
- try:
return eval(expression)- result = eval(expression)
- return int(result)
- except:
return 0- return "Invalid expression. Please try again."
from solution import * test.assert_equals(Calculator("/", 14, 1), 14) test.assert_equals(Calculator("+", 42, 11), 53) test.assert_equals(Calculator("-", 6, 50), -44) test.assert_equals(Calculator("/", 32, 2), 16) test.assert_equals(Calculator("*", 25, 5), 125) test.assert_equals(Calculator("**", 123, 2), 15129)
test.assert_equals(Calculator("/", 1, 0), 0)- from solution import *
- test.assert_equals(Calculator("/", 14, 1), 14)
- test.assert_equals(Calculator("+", 42, 11), 53)
- test.assert_equals(Calculator("-", 6, 50), -44)
- test.assert_equals(Calculator("/", 32, 2), 16)
- test.assert_equals(Calculator("*", 25, 5), 125)
test.assert_equals(Calculator(123, 2), 0)- test.assert_equals(Calculator("**", 123, 2), 15129)