首页 > 编程知识 正文

python编写bmi计算器,Python计算BMI

时间:2023-12-27 22:26:14 阅读:323933 作者:IZJR

本文目录一览:

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.")

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