Skip to content
Snippets Groups Projects
Select Git revision
  • 4a7e3147c5de58d21c41e38586e34c5f17595793
  • main default
  • final_pytorch
  • phase-1-final
4 results

setup.cfg

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}.")