How to create BMI Calculator Web App using Python and PyWebIO ?
In this article, we are going to create a BMI calculator using the PyWebIO module. This is a python module mostly used to create simple and interactive interfaces on the web using Python programming. It can be installed using the below command:
pip install pywebio
Before creating a calculator let’s take a brief understanding of BMI, The Body Mass Index (BMI) is the value obtained from dividing the weight of a person in Kg by its height square. The SI unit of BMI is kg/m2. Body Mass Index is directly proportional to the mass of an individual and inversely proportional to the square of the height of the individual.
BMI = Mass of person / (height)2 where, Mass in Kilograms(Kg), height in meters(m)
Now, we create a Calculator of BMI using Python and a very interesting library PyWebIO.
Import the required modules. For using the python library PyWebIO we have to import some important modules from this library:
As we can see in the above python program that we first import the required modules from the PyWebIO library. Then we create a class calculation in which we create BMIcalculator() method classifies a person based on the BMI passed as paramete
After that from the user we take two inputs as for calculation we need height, mass, and then we calculate the result BMI by using the BMI formula and pass them as parameters in BMIcalculator() which computes BMI and classifies the weight category as per as result of BMI.
Below is the complete program:
As in the output we take Height (1.7 m) and Mass (60 Kg) at the time of input, and we can see in the output the calculated BMI and their type.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course