首页 > 编程知识 正文

python计算标准体重(用python计算体重指数)

时间:2023-12-18 17:21:43 阅读:317003 作者:PFDI

本文目录一览:

怎样用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.")

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计算BMI值

废话不多说,改进版继续上程序哈:

def bmi():

name=input('Name:')

height=input('Height(m):')

weight=input('Weight(kg):')

BIM=float(float(weight)/(float(height)**2))

print('您的BIM指数为:',BIM)

if BIM 18.5:

print('你太轻了!')

elif BIM=25:

print('标准体重哦哦!')

elif BIM=32:

print('您有点微胖哦哦!')

else:

print('您太胖了,该减肥了')

bmi()

for i in range(10):

choose =input('您是否愿意继续计算BMI(y/n):')

if choose=='y':

bmi()

else:

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])

源代码(注意源代码的缩进)

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。