Python exercise: BMI Calculator

Today I'm working on a couple of small Python coding exercises. This is a little project recommended by Dr. Angela Yu; she's put together some great tutorials that are fun to follow along with. I'll also be posting these to my GitHub account as I proceed through them.

Exercise: Write a program that interprets the results of the Body Mass Index (BMI) based on a user's weight (kg) and height (m).

This program interprets the Body Mass Index (BMI) based on a user's weight and height. If their BMI is:

  • Under 18.5 they are underweight

  • Over 18.5 but below 25 they have a normal weight

  • Over 25 but below 30 they are slightly overweight

  • Over 30 but below 35 they are obese

  • Above 35 they are clinically obese.

    bmi_calculator.py:
    -------------------------------------------------

    height = float(input("enter your height in m: "))
    weight = float(input("enter your weight in kg: "))
    bmi = round(weight / height ** 2)

    if bmi < 18.5:
    print(f"Your BMI is {bmi}, you are underweight.")
    if bmi < 25:
    print(f"Your BMI is {bmi}, you have a normal weight.")
    elif bmi < 30:
    print(f"Your BMI is {bmi}, you are slightly overweight.")
    elif bmi < 35:
    print(f"Your BMI is {bmi}, you are obese.")
    else:
    print(f"Your BMI is {bmi}, you are clinically obese.")

    -------------------------------------------------

Previous
Previous

Python exercise: Leap Year Calculator