Discuss / Python / Learn Time:2020/1/4

Learn Time:2020/1/4

Topic source

HellPlay

#1 Created at ... [Delete] [Delete and Lock User]

随便写的加减乘除,大概就这个意思吧?

def plus(x, y):
    return x + y
def minus(x, y):
    return x - y
def multi(x, y):
    return x * y
def divide(x, y):
    if y!=0:
        return x / y
    else:
        return x*float("inf")
def calculate(x,y,f):
    return f(x,y)
# 计算  2*(3+4)-5/6 = 13.16666
>>> print(calculate(calculate(2,calculate(3,4,plus),multi),calculate(5,6,divide),minus))
...
>>> 13.166666666666666

优秀


  • 1

Reply