0% found this document useful (0 votes)
0 views2 pages

BMI Calculator in Python

The document provides a simple Python program that calculates the Body Mass Index (BMI) based on user input for weight and height. It includes source code for the BMI calculation, categorizes the results into health ranges, and offers instructions on how to run the script. This exercise serves as a beginner-friendly introduction to Python programming concepts such as input/output, functions, and conditional logic.

Uploaded by

zacklygammer567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views2 pages

BMI Calculator in Python

The document provides a simple Python program that calculates the Body Mass Index (BMI) based on user input for weight and height. It includes source code for the BMI calculation, categorizes the results into health ranges, and offers instructions on how to run the script. This exercise serves as a beginner-friendly introduction to Python programming concepts such as input/output, functions, and conditional logic.

Uploaded by

zacklygammer567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

BMI Calculator in Python

Introduction
This is a simple Python program that calculates the Body Mass Index (BMI) of a user based
on their height and weight.

Source Code
def calculate_bmi(weight, height):
bmi = weight / (height ** 2)
return bmi

def main():
print("BMI Calculator")
weight = float(input("Enter your weight in kg: "))
height = float(input("Enter your height in meters: "))
bmi = calculate_bmi(weight, height)
print(f"Your BMI is: {bmi:.2f}")
if bmi < 18.5:
print("You are underweight.")
elif 18.5 <= bmi < 24.9:
print("You have a normal weight.")
elif 25 <= bmi < 29.9:
print("You are overweight.")
else:
print("You are obese.")

if __name__ == "__main__":
main()

Explanation
This Python script asks the user to input their weight (in kilograms) and height (in meters),
calculates the BMI using the standard formula (weight divided by square of height), and
categorizes the result into health ranges.

Sample Output
Enter your weight in kg: 70
Enter your height in meters: 1.75
Your BMI is: 22.86
You have a normal weight.

Conclusion
The BMI Calculator is a great beginner exercise to get comfortable with input/output,
functions, and conditional logic in Python.

How to Run
Save the script as `bmi_calculator.py`, and run it using `python bmi_calculator.py`.

You might also like