阿亮最近在健身,想要通过计算体脂率(BFR)简单判断自己的这段时间的健身效果。
BFR=1.2×BMI+0.23×年龄-5.4-10.8×性别(男为1,女为0);
BMI=体重÷(身高×身高)。
体重单位是千克,身高单位是米
请你定义两个“匿名函数”,分别计算BMI和BFR。
传入参数计算BFR:体重 70,身高 1.75,年龄30,性别男
编写程序判断,如果男性30岁以下体脂率为14-20,30岁及以上体脂率为17-23,输出"你的体脂率为{BFR},健身有效果,继续保持";
若男性体脂率超过25,输出"你的体脂率为{BFR},继续加油健身哦!"
gender={"female":0,"male":1}
BMI=lambda weight,height:weight/(height*height)
BFR=lambda weight,height,age,gender:1.2*BMI(weight,height)+0.23*age-5.4-10.8*gender
result=BFR(70,1.75,30,1)
age=30
gender="male"
if (gender=="male" and age<30 and 14<result<20) :
print(f"你的体脂率为{result},健身有效果,继续保持")
elif gender=="male" and age>=30 and 17<result<23:
print(f"你的体脂率为{result},健身有效果,继续保持")
elif gender=="male" and result>25:
print(f"你的体脂率为{result},继续加油健身哦!")
一位大佬帮助我用字典完成了我想要的效果。