Facebook
From Shahriar, 1 Month ago, written in Python.
Embed
Download Paste or View Raw
Hits: 137
  1. weight = float(input("Enter your weight in kilograms: "))
  2. height_cm = float(input("Enter your height in centimeters: "))
  3.  
  4. if height_cm <= 0:
  5.     print("Height must be greater than 0")
  6. elif weight <= 0:
  7.     print("Weight must be greater than 0")
  8. else:
  9.     height_m = height_cm / 100
  10.     bmi = weight / (height_m ** 2)
  11.    
  12.     if bmi < 18.5:
  13.         category = "Underweight"
  14.     elif 18.5 <= bmi < 24.9:
  15.         category = "Normal weight"
  16.     elif 25 <= bmi < 29.9:
  17.         category = "Overweight"
  18.     else:
  19.         category = "Obesity"
  20.    
  21.     print(f"Your BMI is: {bmi:.2f}")
  22.     print(f"Your BMI category is: {category}")