{"id":25637,"date":"2021-11-23T09:00:34","date_gmt":"2021-11-23T03:30:34","guid":{"rendered":"https:\/\/python-programs.com\/?p=25637"},"modified":"2021-11-23T09:02:09","modified_gmt":"2021-11-23T03:32:09","slug":"python-bmi-calculator","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-bmi-calculator\/","title":{"rendered":"Python BMI Calculator \u2013 A Complete Step-by-Step Tutorial"},"content":{"rendered":"
In this article, we will learn how to develop a Body Mass Index (BMI) Calculator using the Python programming language. But before we begin developing one, let us first define Body Mass Index (BMI).<\/p>\n
BMI, or Body Mass Index, is a measure of relative weight based on an individual’s weight and height. The Body Mass Index is commonly used to classify people based on their height and weight. These classifications include underweight, healthy, overweight, and even obesity. Furthermore, it is being used by a number of countries to promote healthy eating.<\/p>\n
Body Mass Index (BMI) can be used as a substitute for direct measures of body fat. Furthermore, BMI is a low-cost and simple means of screening for weight classes that may cause health problems.<\/p>\n
A BMI Calculator takes an individual’s weight and height and computes their Body Mass Index (BMI).<\/p>\n
The data below illustrates how BMI is classified in order to determine a person’s health state.<\/p>\n
The Formula for Calculating BMI:<\/strong><\/p>\n BMI\u00a0 = (weight)\/(height)^2<\/p>\n where weight\u00a0 in – kg<\/p>\n and height in – m<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n In this article, we will learn how to develop a Body Mass Index (BMI) Calculator using the Python programming language. But before we begin developing one, let us first define Body Mass Index (BMI). Body Mass Index (BMI): BMI, or Body Mass Index, is a measure of relative weight based on an individual’s weight and …<\/p>\nPython Code<\/h3>\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Give the height as static input and store it in a variable.\r\ngvn_height = 2.5\r\n# Give the weight as static input and store it in another variable.\r\ngvn_weight = 45\r\n# Calculate the Body Mass Index(BMI) value using the above given mathematical\r\n# formula and store it in another variable.\r\nrslt_BMI = gvn_weight\/(gvn_height*gvn_height)\r\nprint(\"The BMI value for the given height{\",\r\n gvn_height, \"}\", \"and weight{\", gvn_weight, \"}=\", rslt_BMI)\r\n# Check if the above obtained BMI value is greater than 0 using the if conditional\r\n# statement.\r\nif(rslt_BMI > 0):\r\n # If it is true, then check again if the above obtained BMI value is less than\r\n # or equal to 16.\u00a0\r\n if(rslt_BMI <= 16):\r\n # If it is true, then print \"Person is severely underweight.Please Takecare\".\r\n print(\"Person is severely underweight. Please Takecare\")\r\n # Check if the above obtained BMI value is less than or equal to 18.5 using\r\n # the elif conditional statement.\u00a0\r\n elif(rslt_BMI <= 18.5):\r\n # If it is true, then print \"Person is Underweight\".\r\n print(\"Person is Underweight\")\r\n # Check if the obtained BMI value is less than or equal to 25 using the elif\r\n # conditional statement.\r\n elif(rslt_BMI <= 25):\r\n # If it is true, then print \"Person is Healthy\".\r\n print(\"Person is Healthy\")\r\n # Check if the obtained BMI value is less than or equal to 30 using the elif\r\n # conditional statement.\u00a0\r\n elif(rslt_BMI <= 30):\r\n # If it is true, then print \"Person is Overweight\".\r\n print(\"Person is Overweight\")\r\n else:\r\n # Else print \"Person is suffering from Obesity\".\r\n print(\"Person is suffering from Obesity\")\r\n# Else print \"Invalid Input\".\r\nelse:\r\n print(\"Invalid Input\")\r\n<\/pre>\n
The BMI value for the given height{ 2.5 } and weight{ 45 }= 7.2\r\nPerson is severely underweight. Please Takecare<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Give the height as user input using the float(input()) function and store it in a variable.\r\ngvn_height = float(input(\"Enter height(m) = \"))\r\n# Give the weight as user input using the float(input()) function and store it in another variable.\r\ngvn_weight = float(input(\"Enter Weight(Kg) = \"))\r\n# Calculate the Body Mass Index(BMI) value using the above given mathematical\r\n# formula and store it in another variable.\r\nrslt_BMI = gvn_weight\/(gvn_height*gvn_height)\r\nprint(\"The BMI value for the given height{\",\r\n gvn_height, \"}\", \"and weight{\", gvn_weight, \"}=\", rslt_BMI)\r\n# Check if the above obtained BMI value is greater than 0 using the if conditional\r\n# statement.\r\nif(rslt_BMI > 0):\r\n # If it is true, then check again if the above obtained BMI value is less than\r\n # or equal to 16.\u00a0\r\n if(rslt_BMI <= 16):\r\n # If it is true, then print \"Person is severely underweight.Please Takecare\".\r\n print(\"Person is severely underweight. Please Takecare\")\r\n # Check if the above obtained BMI value is less than or equal to 18.5 using\r\n # the elif conditional statement.\u00a0\r\n elif(rslt_BMI <= 18.5):\r\n # If it is true, then print \"Person is Underweight\".\r\n print(\"Person is Underweight\")\r\n # Check if the obtained BMI value is less than or equal to 25 using the elif\r\n # conditional statement.\r\n elif(rslt_BMI <= 25):\r\n # If it is true, then print \"Person is Healthy\".\r\n print(\"Person is Healthy\")\r\n # Check if the obtained BMI value is less than or equal to 30 using the elif\r\n # conditional statement.\u00a0\r\n elif(rslt_BMI <= 30):\r\n # If it is true, then print \"Person is Overweight\".\r\n print(\"Person is Overweight\")\r\n else:\r\n # Else print \"Person is suffering from Obesity\".\r\n print(\"Person is suffering from Obesity\")\r\n# Else print \"Invalid Input\".\r\nelse:\r\n print(\"Invalid Input\")\r\n<\/pre>\n
Enter height(m) = 1.5\r\nEnter Weight(Kg) = 59\r\nThe BMI value for the given height{ 1.5 } and weight{ 59.0 }= 26.22222222222222\r\nPerson is Overweight<\/pre>\n","protected":false},"excerpt":{"rendered":"