Create BMI Calculator using Python17 Mar 2025 | 4 min read In the following tutorial, we will understand how to create a Body Mass Index (BMI) Calculator with the help of the Python programming language. But we get started creating one; let us briefly discuss what Body Mass Index (BMI) is. Understanding the Body Mass Index (BMI)BMI, short for Body Mass Index, is a measure of relative weight based on the mass and height of an individual. We generally use the Body Mass Index in order to categorize people on the basis of their height and weight. These categories are underweight, healthy, overweight, and even obesity. Moreover, it is also adopted by various countries in order to promote healthy eating. We can consider Body Mass Index (BMI) as a substitute for direct measurements of body fat. Besides, BMI is a low-cost and easy-to-perform method of screening for weight classes that may cause health-related problems. Understanding the working of BMI CalculatorA BMI Calculator accepts the weight and height of an individual and calculates the Body Mass Index (BMI) of that person. For Example, if the height and weight of a person are 155 cm and 57 kg. The BMI of that person will be 23.73 (approx.), which signifies that the person is healthy. Body Mass Index (BMI) is a measure of body fat on the basis of height and weight, respectively. On the basis of the BMI of an individual, the calculator returns a statement stating the overall health of the person. The following table shows how the classification of BMI is done in order to identify the health status of a person.
Now, let us begin coding the project. Creating BMI Calculator using PythonAs the first step, we will create a New Python program file and name it BMI_Calculator.py. Within this file, we will begin by creating a block of code to ask the user their height and weight. We can easily accomplish this using the input() function. File: BMI_Calculator.py Explanation: In the above snippet of code, we have defined two variables as the_height and the_weight which uses the input() function to accept input from the user. We have also included the float() function outside the input() function in order to convert the input string into the float data type so that we can perform calculations with it. Next, we will calculate the Body Mass Index. We will use the following formula in order to calculate BMI. ![]() Let us implement the above formula in the Python program. File: BMI_Calculator.py Explanation: In the above snippet of code, we have defined a function for BMI using the above formula. We have divided the height by 100 to convert the centimeters into meters. Now, let us print the BMI. File: BMI_Calculator.py Explanation: In the above snippet of code, we have printed a statement stating BMI of the person. Now, we will print the statement stating the present health of the user based on their BMI. This block of code will be quite simplified for better understanding. We will use the if-elif-else conditions for classification. File: BMI_Calculator.py Explanation: In the above snippet of code, we have used the value of the variable the_BMI in the if-elif-else statement to check if the BMI of the person lies within one of the categories. The program will print the statement on the following basis:
Hence, the program is completed. Let us see the complete source code for the program and output for the same. Source CodeFile: BMI_Calculator.py Output: Enter the height in cm: 160 Enter the weight in kg: 61 Your Body Mass Index is 23.828124999999996 Awesome! You are healthy. Next TopicString to Binary in Python |
C Vs. C++ Vs. Python Vs. Java Programs have become an inseparable part of our daily lives. Everything is now digitised and connected through the Internet of Things. C, C++, Java, and Python remain at the top of the charts for popular programming languages among most...
7 min read
? In Python, you can use whitespace to define code blocks and space (also known as indentation) to organize your code. Indentation is crucial in Python because it establishes the hierarchy and scope of statements within control structures like loops, conditional statements, and function definitions. Correct indentation...
4 min read
? The CSV file stands for a comma-separated values file. It is a type of plain text file where the information is organized in the tabular form. It can contain only the actual text data. The textual data don't need to be separated by the commas (,)....
2 min read
We split a collection of items into two halves in Binary Search to decrease the number of direct comparisons needed to discover an element. However, there's one requirement: the array's items must be sorted beforehand. Binary Search The Binary Search Method locates the index of a certain list...
4 min read
The logarithm function is the inverse of the exponential function. If we have an exponential equation, such as 2^3 = 8, we can rewrite it as a logarithmic equation: log2(8) = 3. Python's log base 2 functions can be accessed through the built-in math module. The...
2 min read
This tutorial will show how to leverage the Python machine-learning models to predict outcomes using the Sklearn predict function. So we will briefly summarise what the function accomplishes, review the syntax, and then provide examples of using this method with various machine learning models. A Brief Overview of...
5 min read
Python has gained so much popularity and has become the highly demanded programming language in the industry. There are many reasons developers show their love for this programming language, such as versatile, rich libraries, friendly syntax, ease of learning, and many others. And another interesting reason...
5 min read
In today's world, people mostly utilize the internet to perform several tasks. Online compilers are one of those, and most people run their programs through online compilers instead of installing compilers. In this article, you will learn about the best python online compilers. There are several...
9 min read
Bar plots are a popular way to represent data visually in Python. They are especially useful for comparing the values of different categories or groups. In this tutorial, we will learn how to create a bar plot (easy to advance) in Python using the Matplotlib library. Before...
4 min read
This tutorial will teach us about character encoding and number systems. We will explore how encoding is used in Python with string and bytes and numbering systems through its various forms of int literals. Let's have an introduction to character encoding in Python. What is Character Encoding? There...
8 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India