# 体脂率计算(优化版)
personH = input('请输入您的身高(m)')
personH = eval(personH) # 输入数据是什么,eval()就会显示为原始数据的类型
if 0 < personH <3:
personH = personH
else:
print('输入错误')
exit()#表示退出程序
personW = input('请输入您的体重(kg)')
personW = eval(personW)
if 0 < personH <300:
personW = personW
else:
print('输入错误')
exit()
personA = input('请输入您的年龄')
personA = eval(personA)
if 0 < personA <150:
personA = personA
else:
print('输入错误')
exit()
personS = input('请输入您的性别')
# personS = eval(personS)
if personS == '男':
personS = 1
elif personS == '女':
personS = 0
else:
print('输入错误')
exit()
# 数据处理
# BMI=体重(kg)/(身高*身高)(m)
# TZV= 1.2*BMI+0.23*年龄-5.4-10.8*性别(男:1,女:0)
# 男性体脂率正常范围15%-18%,女性体脂率正常范围25%-28%,
BMI = personW / (personH * personH)
TZV = 1.2 * BMI + 0.23 * personA - 5.4 - 10.8 * personS
TZV /= 100
if personS == 1 and 0.15 <= TZV <=0.18:
print(TZV)
print('先生您好,恭喜您,身体非常棒,请继续保持')
elif personS == 1 and TZV > 0.18:
print(TZV)
print('先生您好,请注意,您的身体偏胖')
elif personS == 1 and TZV < 0.15:
print(TZV)
print('先生您好,请注意,您的身体偏瘦')
if personS == 0 and 0.25 <= TZV <= 0.28:
print(TZV)
print('女士您好,恭喜您,身体非常棒,请继续保持')
elif personS == 0 and TZV > 0.28:
print(TZV)
print('女士您好,请注意,您的身体偏胖')
elif personS == 0 and TZV < 0.25:
print(TZV)
print('女士您好,请注意,您的身体偏瘦')
5python 体脂率计算(优化版)
最新推荐文章于 2024-01-10 09:22:15 发布