首页 > 编程知识 正文

python实现体重指数计算器的简单介绍

时间:2023-12-27 22:28:00 阅读:327120 作者:RSJW

本文目录一览:

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

用C#编写一个计算体重指数的控制台程序。

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("体重指数计算器 n 使用帮助:根据提示输入,再按"回车确定" ");

start:

Console.WriteLine("输入你的身高:单位:米(m)");

double height = Convert.ToDouble(Console.ReadLine());

Console.WriteLine("输入体重: 单位:千克(kg)");

double weight = Convert.ToDouble(Console.ReadLine());

if (height = 0 || weight = 0)

{

Console.WriteLine("你输入的数字有误,按'1'重新开始! 注意:按其他键将会退出程序!");

byte i = Convert.ToByte(Console.ReadLine());

switch (i)

{

case 1:

goto start;

break;

default:

return;

break;

}

}

else

{

double bmi = weight / (height * height);

Console.WriteLine("你的体重指数为{0}",bmi );

if (bmi 18.5)

Console.WriteLine("偏瘦,危险性:低,但其它疾病危险性增加");

else if (bmi = 18.5 bmi 24)

Console.WriteLine("正常,请继续保持");

else if (bmi = 24 bmi 27)

Console.WriteLine("偏重,危险性:小");

else if (bmi = 27 bmi 30)

Console.WriteLine("肥胖,危险性:中");

else if (bmi = 30 bmi 40)

Console.WriteLine("重度肥胖,危险性:大");

else

Console.WriteLine("极度肥胖,危险性:极大");

}

Console.WriteLine("n是否想重新使用? 是按'1' 否按'2'来退出程序。");

byte a = Convert.ToByte(Console.ReadLine());

switch (a)

{

case 1:

goto start;

break;

case 2:

return;

break;

default:

return;

break;

}

Console.ReadKey();

}

}

}

怎样用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题,是关于定义函数和身体指数的,谢谢各位大神啦!!!

按照题目要求编写的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简单题不会,求解答

#第一题:

from __future__ import division

print '请依次输入体重(kg)与身高(m):'

weight = float(raw_input())

height = float(raw_input())

print "{:.2f}".format(weight/(height**2))

#第二题:

print '请输入一个秒数:'

sec = int(raw_input())

print str(sec/3600)+' '+str(sec%3600/60)+' '+str(sec%60)

#第三题:

from __future__ import division

import math

print '请依次输入三角形三边值a, b ,c:'

a = int(raw_input())

b = int(raw_input())

c = int(raw_input())

print "{:.1f}".format(math.degrees(math.acos((a**2 + b**2 - c**2)/(2*a*b))))

你复制的 问题还复制不全,汗啊。。。这么多问题 连个分也没有。。。人家计算BMI是用的平方,你这里还给了个错的公式,还能不能认真点儿。

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