Python,Calculating with Functions

# codewars,Calculating with Functions


'''
seven(times(five())) # must return 35
four(plus(nine())) # must return 13
eight(minus(three())) # must return 5
six(divided_by(two())) # must return 3
'''

def same(x): return x
def zero(func=same): return func(0) 
def one(func=same): return func(1) 
def two(func=same): return func(2) 
def three(func=same): return func(3) 
def four(func=same): return func(4) 
def five(func=same): return func(5) 
def six(func=same): return func(6) 
def seven(func=same): return func(7) 
def eight(func=same): return func(8) 
def nine(func=same): return func(9) 

def plus(y): return lambda x:x+y
def minus(y): return lambda x:x-y
def times(y): return lambda x:x*y
def divided_by(y): return lambda x:int(x/y)
# int()函数将小数截去小数部分,转化为整数

# 或者
# def divided_by(y): return lambda x:x//y
# //是整数除法运算符,执行除法运算并返回商的整数部分
posted @ 2025-03-07 20:35  Kazuma_124  阅读(10)  评论(0)    收藏  举报