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))
你可以先学习一些python基础再来试着写函数,对基础的内容有些了解,才能理解函数的意义
拿这个来说,起码要知道参数传参,if的用法,函数返回值的写法等等,我都不知道怎么评价了,好多错误😂