Skip to content

Checking your reading list…

Retry verification

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Calculating Body Mass Index (BMI) with Python
Fundamentals 4 min read

Calculating Body Mass Index (BMI) with Python

This tutorial explains how to use Python to input a person's height and weight, compute the Body Mass Index using the standard formula, interpret the result according to international categories, and provides a complete code example while noting BMI's health limitations.

Body Mass Index (BMI) is a common metric to assess whether a person is underweight, normal weight, overweight, or obese based on height and weight.

The BMI formula is BMI = weight(kg) / (height(m) * height(m)).

First, the program prompts the user to input height (in meters) and weight (in kilograms) using height = float(input("请输入您的身高(米):")) and

weight = float(input("请输入您的体重(公斤):"))

.

It then computes the BMI with bmi = weight / (height * height).

The result is interpreted according to international standards: BMI < 18.5 (underweight), 18.5‑24.9 (normal), 25‑29.9 (overweight), ≥30 (obese). An if‑elif‑else block prints the appropriate category.

A complete example combines the input, calculation, and classification logic, showing how Python can be used for simple numerical analysis.

The article also notes that BMI is only one health indicator and should be considered alongside other factors and professional advice.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

Report an issue with this article
programmingbasicsBMI

Reader feedback

Was this useful?

Useful0

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion