- Handle missing arg; use args variable in function definitions.
- validate 1st arg is a string sign.
- validate args has 3 arg.
def v_sign(s): return s in '+-*/' def v_args(a): return len(a) == 3 def Calculator(*args): if not (v_sign(str(args[0])) and v_args(args)): return 0 sign, n1, n2 = args match(sign): case "+": return n1+n2 case "-": return n1-n2 case "*": return n1*n2 case "/": if n2==0: return 0 return n1/n2 case _: return 0
def Calculator(sign: str, n1: int, n2: int):- def v_sign(s):
- return s in '+-*/'
- def v_args(a):
- return len(a) == 3
- def Calculator(*args):
- if not (v_sign(str(args[0])) and v_args(args)):
- return 0
- sign, n1, n2 = args
- match(sign):
- case "+":
- return n1+n2
- case "-":
- return n1-n2
- case "*":
- return n1*n2
- case "/":
- if n2==0:
- return 0
- return n1/n2
- case _:
- return 0