Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Python Program to Calculate BMI

    Python Programming Examples


    This Python program calculates Body Mass Index (BMI); it uses a simple formula to measure the amount of body fat based on a person's weight and height.

    Python Program to Calculate BMI

    Example:

    This Python program asks for user inputs, validates them, and performs simple calculations via a formula to obtain the BMI index.

    while True:
        try:
            # Taking user input
            Height = float(input("Please enter your height in inches: "))
            Weight = float(input("Please enter your weight in pound: "))
        except ValueError:
            # Validation error.
            print("Please provide valid input.")
            continue  # Return to the start of the loop.
        else:
            if Height <= 0 or Weight <= 0:
                print("Your input must not be zero or less.")
                continue
            else:
                # Calculate BMI
                BMIIndex = round(Weight / (Height * Height) * 703, 2)
    
                # Print the output
                print("Your Body Mass Index is: ", BMIIndex)
    
                if BMIIndex < 18.5:
                    print("Underweight.")
                elif BMIIndex <= 24.9:
                    print("Normal.")
                elif BMIIndex <= 29.9:
                    print("Overweight.")
                else:
                    print("Obese.")
            break

    Output:

    Please enter your height in inches: 72
    Please enter your weight in pound: 181
    Your Body Mass Index is:  24.55
    Normal.

    What Is Body Mass Index (BMI)

    Body mass index is called BMI, which measures the amount of body fat based on a person's weight and height. As per the WHO (World Health Organization), The standard BMI value is 18.5 to 24.9; If BMI falls in this range, a person's body height and weight ratio are considered healthy. A BMI less than 18.5 indicates a very skinny and underweight person who needs to increase their calorie and carbohydrate content. A BMI greater than 25 to 29.9 indicates that the person is overweight. A BMI above the range of 30 is considered very dangerous. And such a person can be classified as obese.

    BMI Formulas

    This Python program uses the formula below to calculate the BMI:

    BMI = [weight (pound) / height2 (inches) ]* 703

    Example:

    For example, a person's weight is 181 lbs, and his height is 72 inches. So let's know what his BMI is?

    Height: 72 inches
    Square of height: (72 * 72), m2 = 5182
    Weight: 181 lbs
    BMI = 181/5182*703 = 24.55
    Python Syntax:
    print(round(Weight/(Height*Height)* 703,2));

    This BMI calculator is not clinical guidance nor a substitute for professional medical advice. Since BMI depends on weight and height, it is only an indicator of body obesity. The amount of fat in individuals with the same BMI may vary. Individuals may consider seeking advice from their healthcare providers.



    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.