if 语句


personHeight = input("请输入你的身高(m)")
personHeight = float(personHeight)
personWeight = input("请输入你的体重(kg)")
personWeight = float(personWeight)
personAge = input("请输入你的年龄:")
personAge = int(personAge)
personSex = int(input("请输入你的性别(男:1,女:0)"))
personSex = int(personSex)

#容错处理,数据有效性的验证

if not (0 < personHeight < 3 and 0 < personWeight < 300 and 0 < personAge < 150 and (personSex == 1 or personSex == 0)):
print("输入的数据有误")
exit()


BMI = personWeight / (personHeight * personHeight)
TZL = (1.2 * BMI + 0.23 * personAge - 5.4 - 10.8 * personSex) / 100

# if personSex == 1:
# print("男性的体脂率为0.15----0.18")
# elif personSex == 0:
# print("女性的体脂率为0.25---0.28")
# else:
# print("输入有误")
minNum = 0.15 + 0.10 * ( 1 - personSex )
maxNum = 0.18 + 0.10 * ( 1 - personSex )
re = minNum <= TZL <= maxNum
# print("你的体脂率是:%f" % TZL )
# print("你的体脂率是否符合标准",re)
if personSex == 1:
n = "先生您好"
minNum = 0.15
maxNum = 0.25
elif personSex == 0:
n = "女士您好"
minNum = 0.18
maxNum = 0.28
else:
print("输入有误")

if re:
m = "您的身体良好,请保持"
else:
if TZL > maxNum:
m = "您的身体偏胖"
else:
m = "您的身体偏瘦"
print(n,m)




posted @ 2020-05-25 16:06  春天的风情  阅读(524)  评论(0编辑  收藏  举报