Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

Create a BMI Calculator Command Line Using Python Functions

Create a BMI Calculator Command Line Using Python Functions

Create a BMI Calculator Command Line Tool Using Python Functions, in this tutorial you will learn how to build a command-line BMI calculator using Python functions. This tutorial covers Python basics, function creation, and command-line interface development.

In today’s world of health consciousness, Body Mass Index (BMI) remains a widely used metric to categorize individuals based on their weight and height. What better way to practice Python programming than by creating a practical tool? In this tutorial, we’ll build a command-line BMI calculator using Python functions.

BMI Calculator GUI Tutorial Python Tkinter BMI Calculator using Java BMI Calculator using Java Script

What is BMI? BMI is calculated using the formula:

bmi = (weight * 10000) / (height * height)

Note:  Weight in KG and Height in CM
The resulting value falls into categories:

Underweight: BMI < 18.5
Normal weight: 18.5 ≤ BMI < 24.9
Overweight: BMI > 24.9

Create a BMI Calculator Command Line Using Python Functions

Building Our BMI Calculator

Let’s create a Python script that calculates BMI based on user input and provides the corresponding category. create a file name bmi.py.

Create a BMI Calculator Command Line  Using Python Functions Code

# Bmi Calculator using function
def calBmi(height,weight):
  # BMI = [weight (kg) / (height (cm))²] x 10000
  bmi = (weight * 10000) / (height * height)
  bmi=round(bmi, 1)
  return bmi

def bmiLevel(bmi):
    if bmi>24.9:
      print("Over weight")
    elif bmi<18.5:
      print("Under weight")
    else:
      print("Normal")
#Taking values from keyboard
print("Enter Weight in KG: ",end=" ")
wet=float(input())
print("Enter Height in CM: ",end=" ")
het=float(input())

bm=calBmi(het,wet)

print(bm)
bmiLevel(bm)
print("Normal Bmi range 18.5 - 24.9")

Run bmi.py:  Open Command Prompt / Terminal / konsole and navigate to directory having file bmi.py, and run command given below

python ./bmi.py

or

python3 ./bmi.py

If you have and query or suggestion or need assistance  then please contact me, I will reply to fix your problem, if you like our content then you can subscribe to our Youtube channel. If you want to hire me then reach us at our Fiverr.

5 1 vote
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments