Skip to content
Snippets Groups Projects
Select Git revision
  • 9293b1a0229d5f09ed2c4b6da21a6288d96a8ab9
  • master default
2 results

dshlib.c

Blame
  • bmi.py 1.12 KiB
    
    
    def poundsToKg(pounds):
        return pounds / 2.205
    
    def feetAndInchesToMeters(feet, inches):
        totalInches = feet * 12 + inches
        return totalInches * 0.0254
    
    # Caution: Weight in kg, height in meters
    def calculateBMI(weight, height):
        return weight / (height * height)
    
    def getBMICategory(bmi):
        if bmi >= 30:
            category = "Obese"
        elif bmi >= 25:
            category = "Overweight"
        elif bmi >= 18.5:
            category = "Normal Weight"
        else:
            category = "Underweight"
        return category
    
    # TODO: Add try/except and conditions to make sure users
    # enter valid values for height and weight
    
    weight = float(input("Enter weight in pounds: "))
    print("Next, you will enter you height in feet and inches, separately.")
    feet = int(input("Enter feet part of height: "))
    inches = int(input("Enter inches part of height: "))
    
    metricHeight = feetAndInchesToMeters(feet, inches)
    metricWeight = poundsToKg(weight)
    yourBMI = calculateBMI(metricWeight, metricHeight)
    
    category = getBMICategory(yourBMI)
    
    print(f"At {feet} feet and {inches} inches tall at a weight of {weight} pounds, your BMI is {yourBMI:.1f}, which is {category}.")