A program that asks for a few kilograms to reach BMI and standard weight [Python]

In this article A program that asks for a few kilograms from height and weight to BMI and standard weight I will write.

What is BMI / standard weight?

The body mass index (body mass index) is a body mass index that represents the degree of obesity in humans, which is calculated from the relationship between body weight and height. Generally called BMI (Body Mass Index). Body Mass Index-Wikipedia

Normal body weight is the ideal body weight that is statistically certified to be the healthiest human being, with significantly lower mortality and morbidity over a period of time. , Age, height, body fat percentage, etc., all or part of the factors. standard weight-Wikipedia

How to find

BMI BMI = w ÷ (h × h) ** Standard weight ** Standard weight (kg) = (height (m) x height (m)) x 22

Write the code

** Create a function to calculate BMI and standard weight ** First, pass two arguments to the function. The first is weight The second is height

Since it is only a few kilograms to display the BMI and the appropriate weight, Current weight-standard weight Then find how many kg (difference).

By the way, the unit of height to be acquired this time is "cm", so it is necessary to return it to "m".

bmi.py


def getBmi(weight, height):
    #Convert height from cm to m
    height /= 100

    bmi = weight / height ** 2
    appropriate = height ** 2 * 22
    difference = weight - appropriate

** Find and display body shape from BMI ** What is displayed How many kg is left to BMI / body shape / standard weight is. Body types are classified into three types: lean type (<18.5), standard (18.5 <25), and obese type (> = 25). We will conditionally branch this.

bmi(2).py


    if bmi < 18.5:
        print("BMI: ", '{:.1f}'.format(bmi), "Skinny type up to standard weight", '{:.1f}'.format(difference), "kg increase")
    elif bmi < 25:
        print("BMI: ", '{:.1f}'.format(bmi), "standard")
    elif bmi >= 25:
        print("BMI: ", '{:.1f}'.format(bmi), "Obesity up to standard weight", '{:.1f}'.format(difference), "kg weight loss")

The sentence'{: .1f}'.format (bmi) is used to display up to the first decimal place. Also, since it is not necessary to increase or decrease the weight at the time of standard weight, the remaining weight is not displayed.

** Get data and call a function ** Get height and weight in decimal. You can get the decimal number with float (input ()).

bmi(3).py


w = float(input("Please enter your weight.(kg) → "))
h = float(input("Please enter your height.(cm) → "))

getBmi(w, h)

Overall picture

bmi(4).py


def getBmi(weight, height):
    height /= 100

    bmi = weight / height ** 2
    appropriate = height ** 2 * 22
    difference = weight - appropriate

    if bmi < 18.5:
        print("BMI:", '{:.1f}'.format(bmi), "Skinny type up to standard weight", '{:.1f}'.format(difference), "kg increase")
    elif bmi < 25:
        print("BMI:", '{:.1f}'.format(bmi), "standard")
    elif bmi >= 25:
        print("BMI:", '{:.1f}'.format(bmi), "Obesity up to standard weight", '{:.1f}'.format(difference), "kg weight loss")

w = float(input("Please enter your weight.(kg) → "))
h = float(input("Please enter your height.(cm) → "))

getBmi(w, h)

Execution result

Please enter your weight.(kg) → 65
Please enter your height.(cm) → 170
→ BMI: 22.5 standard

Please enter your weight.(kg) → 90
Please enter your height.(cm) → 160
→ BMI: 37.1 Obesity 38 to normal weight.7 kg weight loss

Summary

This time, A program that asks for a few kilograms from height and weight to BMI and standard weight I wrote.

Basically, I think it's a simple code, so please refer to it.

Thank you very much.

reference

Body Mass Index-Wikipedia standard weight-Wikipedia

Recommended Posts

A program that asks for a few kilograms to reach BMI and standard weight [Python]
I want to exe and distribute a program that resizes images Python3 + pyinstaller
A standard way to develop and distribute packages in Python
How to write a metaclass that supports both python2 and python3
[Python] A program to find the number of apples and oranges that can be harvested
Understand the probabilities and statistics that can be used for progress management with a python program
Try to write a program that abuses the program and sends 100 emails
A quick guide to PyFlink that combines Apache Flink and Python
A program that answers a few questions and predicts the next answer
[Python] A program that rotates the contents of the list to the left
[Python] A program that calculates the number of socks to be paired
A python program that resizes a video and turns it into an image
[Python] It was very convenient to use a Python class for a ROS program.
How to stop a program in python until a specific date and time
[Python] A program that creates stairs with #
A program that plays rock-paper-scissors using Python
[Python] A program that rounds the score
A Python program that checks if any content has been updated and git commits & pushes it to GitLab if it has been updated.
[Python] A program that finds the minimum and maximum values without using methods
[Python] A program that calculates the number of updates of the highest and lowest records
A nice nimporter that connects nim and python
A program that removes duplicate statements in Python
A program that searches for the same image
Let's write a Python program and run it
A Python script that crawls RSS in Azure Status and posts it to Hipchat
How to use pip, a package management system that is indispensable for using Python
I made a program to convert images into ASCII art with Python and OpenCV
A note that runs an external program in Python and parses the resulting line
A python script that wants to use Mac startup / end time for attendance management
Building a Docker working environment for R and Python
I made a VM that runs OpenCV for Python
[Introduction to python] A high-speed introduction to Python for busy C ++ programmers
From buying a computer to running a program with python
Python program that looks for the same file name
[Python] How to write a docstring that conforms to PEP8
A program to write Lattice Hinge with Rhinoceros with Python
[Python] A convenient library that converts kanji to hiragana
Python # How to check type and type for super beginners
[Python] A program that compares the positions of kangaroos.
A Python program that converts ical data into text
I made a toolsver that spits out OS, Python, modules and tool versions to Markdown
[C / C ++] Pass the value calculated in C / C ++ to a python function to execute the process, and use that value in C / C ++.
How to start a simple WEB server that can execute cgi of php and python
Python error messages are specific and easy to understand "ga" (before that, a colon (:) and a semicolon (;))
A learning roadmap that allows you to develop and publish services from scratch with Python
A story that makes it easy to estimate the living area using Elasticsearch and Python
A note that deployed a Python application from Circle CI to Elastic Beanstalk and notified Slack
The shortest memo for building a python environment that takes less than 5 minutes to work.
A program that automatically resizes the iOS app icon to the required image size in Python
How to start the PC at a fixed time every morning and execute the python program
Summary of points to keep in mind when writing a program that runs on Python 2.5
I made a program to collect images in tweets that I liked on twitter with Python
Seeking a unified way to wait and get for state changes in Selenium for Python elements
Let's create a program that automatically registers ID/PW from CSV to Bitwarden with Python + Selenium
A program that failed when trying to create a linebot with reference to "Dialogue system made with python"
A Python program that collects tweets containing specific keywords daily and saves them in csv