使用Python编写计算BMI值的程序

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 前言
  • 一、BMI是什么?
  • 二、使用步骤
  • 1.简单代码
  • 2.结果
  • 总结

  • 前言

    Python编写一个程序来计算 BMI 值:

    一、BMI是什么?

    小時候都會算的BMI指數,用身高作為基準,計算出你的體重是過重、標準還是過輕,但是因為BMI指數的參考標準只有身高以及體重,並沒有辦法很精確的測量出身體的組成成分。而現在大家都在測的則是inbody,可以測量出更詳細的身體數據。這篇文章就來告訴你BMI值到底是什麼、怎麼算,以及它跟inbody差在哪。

    二、使用步骤

    1.简单代码

    代码如下(示例):

    #Calculate BMI
    
    height=float(input("Enter your height(m) :"))    #input number for float(m)
    weight=float(input("Enter your wegiht(Kg) :"))   #input number for float(kg)
    BMI=float(weight/pow(height,2))     #Calculate BMI
    print("Your BMI is:",'%.2f'% BMI)   #format the value in 2 decimal places.
    

    2.结果

    代码如下(示例):

    == RESTART: E:\IVE\Semester-4\Embeded System\Lab1\BMI calc ( Q1 ) .py ==
    Enter your height(m) :1.8
    Enter your wegiht(Kg) :74
    Your BMI is: 22.84
    


    总结

    还可以添加条件判断来实现其它功能。

    #Calculate BMI
    
    height=float(input("Enter your height(m) :"))    #input number for float(m)
    weight=float(input("Enter your wegiht(Kg) :"))   #input number for float(kg)
    BMI=float(weight/pow(height,2))     #Calculate BMI
    print("Your BMI is:",'%.2f'% BMI)   #format the value in 2 decimal places.
    
    #Analyzing conditions
    if BMI<18.5:
        print("-Below")
    elif BMI>=18.5 and BMI<24:
        print("-Normai")
    else:
        print("-Over")

    物联沃分享整理
    物联沃-IOTWORD物联网 » 使用Python编写计算BMI值的程序

    发表评论