0% found this document useful (0 votes)
17 views7 pages

CODING

The document outlines a BMI Calculator program that calculates a user's Body Mass Index based on their weight and height, providing advice based on the resulting BMI category. It includes steps for user input, input validation, BMI calculation, and displaying the corresponding health advice. The program aims to be user-friendly and informative, guiding users on maintaining or improving their health based on their BMI results.

Uploaded by

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

CODING

The document outlines a BMI Calculator program that calculates a user's Body Mass Index based on their weight and height, providing advice based on the resulting BMI category. It includes steps for user input, input validation, BMI calculation, and displaying the corresponding health advice. The program aims to be user-friendly and informative, guiding users on maintaining or improving their health based on their BMI results.

Uploaded by

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

CODING

# Introduction to the program


print("Welcome to the BMI Calculator!")
print("This program helps you calculate your Body
Mass Index (BMI) based on your weight and height.")
print("BMI is a measure of body fat based on weight in
relation to height.")
print("It will also give you some advice based on your
BMI.\n")
# Step 1: Take user input for weight and height
try:
weight = float(input("Enter your weight in kilograms
(e.g., 70.5): "))
height = float(input("Enter your height in meters
(e.g., 1.75): "))
# Step 2: Validate the input
if weight <= 0 or height <= 0:
print("Weight and height must be positive
numbers. Please restart the program.")
else:
# Step 3: Calculate BMI
bmi = weight / (height**2)
# Step 4: Display BMI result and advice
print("\nYour BMI is: {:.2f}".format(bmi))
print("Based on your BMI, here is what it means
and what you can do:\n")
if bmi < 18.5:
print("Category:You are underweight.")
print(“Advise:you should consider gaining weight
in a healthy way. Focus on a balanced diet rich in
calories , including whole grains, nuts, fruits, and
vegetable. Consult a healthcare provider for
personalized advise.”
elif 18.5 <= bmi < 24.9:
print("Category:You have a normal weight.")
print("Advice: Great job maintaining a healthy
weight! Continue to eat a balanced diet and stay
physically active to keep your BMI in this range.")
elif 25 <= bmi < 29.9:
print("Category:You are overweight.")
print("Advice: Consider adopting a healthier
lifestyle. Include regular exercise, such as walking,
jogging, or yoga, and monitor your calorie intake.
Consult a nutritionist if needed.")
else:
print("Category:You are obese.")
print("Advice: It’s important to work on reducing
your weight for better health. Focus on a combination
of a nutrient-rich, calorie-controlled diet and regular
physical activity. Seek professional guidance to create a
safe and effective plan.")
except ValueError:
print("Invalid input. Please enter numbers only for
weight and height.")
This project calculates the body mass index(BMI) of the
person.

The algorithm provides step-by-step instructions for


the program's functionality:
1. Start
Display a welcome message introducing the BMI
calculator.
2. Loop until the user decides to exit
Step 2.1: Prompt the user to input their weight (in
kilograms).
Step 2.2: Prompt the user to input their height (in
meters).
3. Validate Input
If the weight or height is not a positive number, display
an error message and return to Step 2.
If the input is invalid (e.g., non-numeric), catch the
error, display an error message, and return to Step 2.
4. Calculate BMI
Use the formula:
\text{BMI} = \frac{\text{weight (kg)}}{\text{height
(m)}^2}
5. Determine BMI Category and Provide Advice
Compare the BMI value against predefined categories:
Underweight: BMI < 18.5
Display the category and advice for gaining weight
healthily.
Normal Weight: 18.5 ≤ BMI < 24.9
Display the category and advice for maintaining the
current weight.
Overweight: 25 ≤ BMI < 29.9
Display the category and advice for losing weight.
Obese: BMI ≥ 30
Display the category and advice for reducing weight
safely.
6. End
Exit the program.
To visualize:
1. Start
2. Input weight and height
3. Validate inputs
If invalid, return to input step
4. Calculate BMI
5. Determine BMI category
Display category and advice
6. End
This algorithm ensures the program is clear, user-
friendly.

You might also like