python Tutorial 8 | lambda

阿嬤
Apr 16, 2021

--

前言

什麼事lambda

程式

加法

x = lambda a : a + 10
print(x(5))
def add2(a):
x = a + 10
return xprint(add2(5))

乘法

x = lambda a, b : a * b
print(x(5, 6))
def multiply2(a, b):
x = a * b
return xprint(multiply2(5, 6))

比大小

x = lambda c, d : c if c > d else  d
print(x(4, 5))
def compare2(c, d):
x = 0
if c > d:
x = c
else :
x = d
return x
print(compare2(5,4))

BMI值

def BMI_calculator(height, weight):
height = float(height)
BMI = 0.0 #歸零
height = height/100 #公分換算成公尺
BMI = weight / (height**2)#體重(公斤)除以(身高的平方)
return BMIprint(BMI_calculator(162,45))x = lambda height, weight : weight / ((height/100)**2)
print(x(162.0, 45.1))

--

--

阿嬤
阿嬤

Written by 阿嬤

歡迎來到湯阿嬤的帝國,如果對體制外的學生的學習精華就來這裡吧,想了解一個體制外學生的日常嗎?想了解繪畫相關的知識嗎?而且,如果有對繪畫有任何的挫折或者阻礙這裡最適合你們!或許你會覺得這裡只是一個憨批在這裡發一些沒有意義的文,但其實,我才是國中生喔!!所以有對這裡有興趣的話,就來這裡吧!

No responses yet