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.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.