新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:利用Python計算身體質(zhì)量指數(shù)BMI來判斷體型
身體質(zhì)量指數(shù)BMI:對身體質(zhì)量的刻畫(Body Mass Index)

國際上常用的衡量人體肥胖和健康程度的重要標(biāo)準(zhǔn),主要用于統(tǒng)計分析。
定義:
有上圖考慮BMI的值的結(jié)果因國內(nèi)和國外的標(biāo)準(zhǔn)不同而不同,故編程將兩種標(biāo)準(zhǔn)均考慮進(jìn)去?。?!
數(shù)據(jù)類型不一致。
1、用int()轉(zhuǎn)換
2、用eval()函數(shù)
先看int()或int(float())效果:
紅色尖頭的細(xì)節(jié)要注意?。?!
tall = int(input("請輸入你的身高(m):"))
heigh =int( float(input("請輸入你的體重(kg):")))
#注意變量 tall 和 heigh 的數(shù)據(jù)類型是字符串,若參與計算,則用eval().
# BMI=體重(kg)/身高^2(m2)
BMI = heigh / pow(tall,2)
if BMI < 18.5 :
print("偏瘦")
elif ((BMI >= 18.5 and BMI <= 25) or (BMI >= 18.5 and BMI <= 24)) :
print("正常")
elif ((BMI > 25 and BMI <= 30) or (BMI >24 and BMI <= 28)) :
print("偏胖")
elif ((BMI > 30) or (BMI >28)) :
print("肥胖")看看eval()函數(shù):
tall = eval((input("請輸入你的身高(m):")))
heigh =eval((input("請輸入你的體重(kg):")))
BMI = heigh / pow(tall,2)
if BMI < 18.5 :
print("偏瘦")
elif ((BMI >= 18.5 and BMI <= 25) or (BMI >= 18.5 and BMI <= 24)) :
print("正常")
elif ((BMI > 25 and BMI <= 30) or (BMI >24 and BMI <= 28)) :
print("偏胖")
elif ((BMI > 30) or (BMI >28)) :
print("肥胖")python創(chuàng)新互聯(lián)教程,免費(fèi)的在線學(xué)習(xí)python平臺,歡迎關(guān)注!
分享題目:創(chuàng)新互聯(lián)Python教程:利用Python計算身體質(zhì)量指數(shù)BMI來判斷體型
轉(zhuǎn)載來于:http://www.dlmjj.cn/article/dpjpggd.html


咨詢
建站咨詢
