函数
格式:
def hanshu(a,b):
#接下来是一些定义函数的代码
c = a + b
print(c)
return c
#执行函数
cos = hanshu(1,2)
实例:
#构建函数判断BMI分类
def calculate_BMI(weight,height):
BMI = weight / height ** 2
if BMI <= 18.5:
category = "偏瘦"
elif BMI <=25:
category ="正常"
elif BMI <=30:
category = "偏胖"
else:
category = "肥胖"
print(f"您的BMI分类为:{category}")
return BMI
result = calculate_BMI(70,1.8)
print(result)