本文目錄一覽:
- 1、python新手簡單程序出錯求修改急求
- 2、Python小白一枚,自己寫的BMI指數計算器,求教高手一下代碼如何重複輸入以及如何結束循環?
- 3、求一道Python題,是關於定義函數和身體指數的,謝謝各位大神啦!!!
- 4、python語言計算BMI值,感謝求解!
- 5、怎樣用python計算bmi
python新手簡單程序出錯求修改急求
% (appelation,first_mame,last_name,feet,inches,weight,b)這裡是7個參數,而前面%r只有6個,應該多加一個。
Python小白一枚,自己寫的BMI指數計算器,求教高手一下代碼如何重複輸入以及如何結束循環?
想讓程序循環,在最外層套一個while就可以了,想跳出的時候寫break就可以了。
在你的代碼中,while不該套在if外面,其次像你這樣判斷直接用if,就可以了,不需要elseif,直接if效率更高。
想跳出,只要寫條件執行break就行,比如下面我的代碼中,輸入N就結束,輸入Y就繼續。
while(1):
print(‘Welcome to use calculator of BMI exponent for human:’)
w = float(input(‘Please enter your weight(kg):’))
h = float(input(‘Please enter your height(m):’))
BMI = w / (h * h)
if BMI 18.5: print(‘you are thin !’)
if 18.5 = BMI =24.9: print(‘you are normal !’)
if BMI =25: print(‘you are little fat !’)
if 25.0 BMI =29.9: print(‘you are more little fat !’)
if 30.0 = BMI = 34.9: print(‘you are fat !’)
if 35.0 = BMI =39.9: print(‘you are serious fat !’)
if BMI =40: print(‘you are extreme fat !’)
print(‘continue?Y/N’)
n=”
while(n!=’Y’ and n!=’N’):
n=input()
if(n==’N’):
break
求一道Python題,是關於定義函數和身體指數的,謝謝各位大神啦!!!
按照題目要求編寫的Python程序如下
def calBMI(height,weight):
BMI=weight/(height*height)
if BMI18.5:
return [BMI,”過輕”]
elif BMI24:
return [BMI,”正常”]
elif BMI28:
return [BMI,”過重”]
else:
return [BMI,”肥胖”]
import re
s=input(“請輸入你的身高(米)和體重(公斤)【逗號隔開】:”)
s1=re.split(r'[,,]’,s)
height=float(s1[0])
weight=float(s1[1])
name=”李子健”
bmi=calBMI(height,weight)
print(“{}的測算結果為:”.format(name))
print(“BMI:%.2f”%bmi[0])
print(bmi[1])
源代碼(注意源代碼的縮進)
python語言計算BMI值,感謝求解!
sg = input(‘你的身高多少(米):’)
tz = input(‘你的體重多少(公斤):’)
BMI = round(float(tz) / float(sg) ** 2, 1)
if BMI 18.5:
print(‘BMI={0},{1}’.format(BMI, ‘偏瘦’))
elif 18.5 = BMI 24.9:
print(‘BMI={0},{1}’.format(BMI, ‘標準’))
elif 25.0 = BMI 29.9:
print(‘BMI={0},{1}’.format(BMI, ‘超重’))
elif 25 = BMI:
print(‘BMI={0},{1}’.format(BMI, ‘肥胖’))
這是委託我讀五年級的兒子寫的。^_^
怎樣用python計算bmi
weight=int(raw_input(“請輸入體重(千克):”))
height=int(raw_input(“請輸入身高(米):”))
BMI=weight/(height*height)
print “BMI=”,BMI
if BMI19:
print“輕體重”
elif BMI=19 and BMI25:
print”健康身體”
elif BMI=25 and BMI28:
print”超重“
else:
print”肥胖”
raw_input(“press any key to quit.”)
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/188604.html