Python 案例一(計算人體體脂率)

來源:互聯網
上載者:User

標籤:blog   輸入   尋找   判斷語句   計算   需要   ons   女性   weight   

#計算人體體脂率#輸入部分#身高personHeight = input("請輸入你的身高(m):")personHeight = float(personHeight)#體重personWeight = input("請輸入你的體重(Kg):")personWeight = float(personWeight)#年齡personAge = input("請輸入你的年齡:")personAge = int(personAge)#性別personSex = input("請輸入你的性別(男:1,女:0):")personSex = int(personSex)#計算部分#   體脂率計算公式#   BMI = 體重(kg) / (身高 * 身高) (米)#   體脂率 = 1.2 * BMI + 0.23 * 年齡 - 5.4 - 10.8 * 性別(1,0)#   男性15%-18%,女性25%-28% 合格BMI = personWeight / (personHeight * personHeight)personGood = 1.2 * BMI + 0.23 * personAge - 5.4 - 10.8 * personSex#   不需要判斷語句的規律尋找minNum = 0.15 + 0.10 * (1 - personSex)maxNum = 0.18 + 0.10 * (1 - personSex)result = minNum < personGood < maxNum# #輸出部分print("你的體脂率為:%.2f"%personGood)print("體脂率是否合格:",result)

 

#計算人體體脂率

#輸入部分
#身高
personHeight = input("請輸入你的身高(m):")
personHeight = float(personHeight)

#體重
personWeight = input("請輸入你的體重(Kg):")
personWeight = float(personWeight)

#年齡
personAge = input("請輸入你的年齡:")
personAge = int(personAge)

#性別
personSex = input("請輸入你的性別(男:1,女:0):")
personSex = int(personSex)

#計算部分
# 體脂率計算公式
# BMI = 體重(kg) / (身高 * 身高) (米)
# 體脂率 = 1.2 * BMI + 0.23 * 年齡 - 5.4 - 10.8 * 性別(1,0)
# 男性15%-18%,女性25%-28% 合格
BMI = personWeight / (personHeight * personHeight)
personGood = 1.2 * BMI + 0.23 * personAge - 5.4 - 10.8 * personSex

# 不需要判斷語句的規律尋找
minNum = 0.15 + 0.10 * (1 - personSex)
maxNum = 0.18 + 0.10 * (1 - personSex)

result = minNum < personGood < maxNum
# #輸出部分

print("你的體脂率為:%.2f"%personGood)

print("體脂率是否合格:",result)

Python 案例一(計算人體體脂率)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.