Pyrhon 單分支和多分支

# 輸入
personHeight = input('請輸入身高(m): ')
personHeight = float(personHeight)
personWeight = input('請輸入體重(kg): ')
personWeight = float(personWeight)
personAge = input('請輸入年齡: ')
personAge = int(personAge)
personSex = input('請輸入性別(男:1 女:0): ')
personSex = int(personSex)


# 容錯處理
if not (0 < personHeight < 3 and 0 < personWeight < 300 and 0 < personAge < 150 and (personSex == 0 or personSex == 1)):
    print('數據不滿足需求')
    exit()



# 處理數據
BMI = personWeight / (personHeight * personHeight)
TZL = 1.2 * BMI + 0.23 * personAge - 5.4 - 18.8 * personSex
TZL /= 100


# 判定體脂率是否在正常範圍
# 男 15% - 18% 女 25% - 28%

if personSex == 1:
    result = 0.15 < TZL < 0.18
elif personSex == 0:
    result = 0.25 < TZL < 0.28


# 輸出
print('你的體脂率,是%f' % TZL)
# print('你的體脂率是否符合標準:', result)

if personSex == 1:
    wenhao = '先生你好:'
    minNum = 0.15
    maxNum = 0.18
elif personSex == 0:
    wenhao = '女士你好:'
    minNum = 0.25
    maxNum = 0.28

if result:
    notice = '恭喜你,身體健康,請保持'
else:
    if TZL > maxNum:
        notice = '請注意,您的身體不正常, 偏胖'
    elif TZL < minNum:
        notice = '請注意,您的身體不正常, 偏瘦'
    

print(wenhao + notice)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章