You need to sign in or sign up before continuing.×
Ad
Code
Diff
  • 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."