******
20230214
******
# 传递参数与参数类型 (位置参数,关键词参数) (初级版)
def trapezoid_area(base_up,base_down,height):
return 1/2 * (base_up + base_down) * height
t = trapezoid_area(1,2,3)
# t1 = trapezoid_area(base_up= 1 ,base_down= 2,height=3)
# t2 = trapezoid_area(height=3,base_up= 1 ,base_down= 2)
# print(t,t1,t2)
print(t)
******
# 传递参数与参数类型 (位置参数,关键词参数) (进阶版)
def trapezoid_area(base_up,base_down,height=3):
return 1/2 * (base_up + base_down) * height
t = trapezoid_area(1,2)
t1 = trapezoid_area(1,2,height=15)
t2 = trapezoid_area(1,2,15)
print(t,t1,t2)
# print(t)
# print(t1)
# print(t2)
******
# 传递参数与参数类型 (位置参数,关键词参数) (高阶版)
temp = int(input("write down the height number: "))
def trapezoid_area(base_up,base_down,height=temp):
return 1/2 * (base_up + base_down) * height
t = trapezoid_area(1,2)
t1 = trapezoid_area(int(input("write down the base_up number: ")),\
int(input("write down the base_down number: ")))
print(t)
print(t1)
******