height,weight = eval(input("请输入身高(米)和体重(公斤)【用逗号隔开】:"))
bmi = weight/pow(height,2)
print("BMI数值为:{:.2f}".format(bmi))
result = ""
if bmi < 18.5:
result = "偏瘦"
elif 18.5 <= bmi < 25:
result="正常"
elif 25 <= bmi <30:
result="偏胖"
else:
result="肥胖"
print("BMI指标为:{0}".format(result))
运行结果
def BMI(x,y):
bmi=y/(x*x)
if bmi<18.5:
print("你身体偏瘦,健康指数是%6.2f"%bmi)
elif bmi<25:
print("你身体标准,健康指数是%6.2f"%bmi)
elif bmi<30:
print("你身体偏胖,健康指数是%6.2f"%bmi)
else:
print("你身体肥胖,健康指数是%6.2f"%bmi)
height=float(input("输入身高(单位:m):"))
weight=float(input("输入体重(单位:kg):"))
BMI(height,weight)
运行结果