bmi_calculator.py

 avatar
unknown
python
5 months ago
1.6 kB
7
Indexable
# Name: Spencer Story
# Date: 12/14/24
# Instructor: Fred Richard
# Assignment: PE2 Final Exam Project
# Course: 2024FA Intro to Prog & Logic (CIS-115-801)


print("💪 Welcome to the Body Mass Index Calculator!💪")

height_in_feet = int(input("Enter your height in feet: "))
height_in_inches = int(input("Enter your height in inches: "))
weight_in_pounds = float(input("Enter your weight in lbs: "))


def bmi_calculator(height_in_feet, height_in_inches, weight_in_pounds):
    if height_in_feet <= 0 or height_in_inches < 0 or weight_in_pounds <= 0:
        return "Error: Invalid input"
    calculate_height_in_inches_total = height_in_feet * 12 + height_in_inches
    calculate_bmi = (weight_in_pounds * 703) / (calculate_height_in_inches_total * calculate_height_in_inches_total)
    if calculate_bmi < 18.5:
        return f"Your Body Mass Index is: {round(calculate_bmi, 1)} Underweight! :("
    elif calculate_bmi <= 24.9:
        return f"Your Body Mass Index is: {round(calculate_bmi, 1)} Normal! :)"
    elif calculate_bmi <= 29.9:
        return f"Your Body Mass Index is: {round(calculate_bmi, 1)} Overweight! :("
    else:
        return f"Your Body Mass Index is: {round(calculate_bmi, 1)} Obese! :("


print_result = bmi_calculator(height_in_feet, height_in_inches, weight_in_pounds)
print(print_result)

# <---List of test cases to use:--->
# print(calculate_bmi(5, 5, 140)) Normal
# print(calculate_bmi(5, 5, 100)) Underweight
# print(calculate_bmi(5, 9, 180)) Overweight
# print(calculate_bmi(5, 9, 225)) Obese
# print(calculate_bmi(5, 9, -5)) Invalid input
Editor is loading...
Leave a Comment