刚开始学 尝试进行函数撰写
def calculator(a, operation, b):
operation = "+" or "-" or "/" or "*"
if operation == "/" and b == 0:
return "cannot divide by zero”)
else operation not == "+" or "-" or "/" or "*"
return "Operation not recognized"
operation = "+" or "-" or "/" or "*"
if operation == "/" and b == 0:
return "cannot divide by zero”)
else operation not == "+" or "-" or "/" or "*"
return "Operation not recognized"
def calculator(a, operation, b):
# operation = "+" or "-" or "/" or "*"
if operation == "/" and b == 0:
return "cannot divide by zero"
elif operation not in ["+","-", "/","*"]:
return "Operation not recognized"
else:
if operation == "/":
return a/b
elif operation =='*':
return a*b
elif operation == '+':
return a+b
else:
return a-b
print(calculator(1, "/", 0))
print(calculator(1, "+", 2))
print(calculator(1, "-", 2))
print(calculator(1, "*", 2))
print(calculator(1, "/", 2))
print(calculator(1, "/,", 2))