Advertisement
kenadams53

Body Mass Index using Python elif

Aug 4th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #Body Mass Index (BMI) calculator in Python code: Writtn by Ken Adams 3rd August 2019
  2. #Formula: BMI = weight in Kilograms divided by the square of hight in meters.
  3. #In this code the BMI is rounded to one decimal place.
  4. #Code Notes: The BMI is calculated and then the user is given advice as to what catogary they belong to.
  5. #Catogries run from hyper obese, obese, overweight, normal, underweight, and severly underweight.
  6. #Reference:The formula and catogories are taken from Wikipedia.
  7. #The 'if' statement recogonises anyone with a BMI over 60 as hyper obese. The next catogory is obese,
  8. #with a range 30 < BMI =< 60. As greater than 60 has already been tested we only need to check if the
  9. #user's BMI is greater than 30; we do this with an 'elif'. Similarly we drop through the other catogories
  10. #with 'elif' statements. The final catogory 'severly underweight' is never tested because we can
  11. #assume that the user is less than 15 if they did not fit any of the other catogories. So at the end
  12. #if-elif block the case less than or equal to 15 is flaged up with an 'else' statement.
  13. weight = float(input("What is your weight in kilograms? "))
  14. height = float(input("What is your height in metres? "))
  15. BMI = weight/height**2
  16. BMI =round(BMI,1)
  17. print("weight " + str(weight) + "kg, " + "height " + str(height) + "m, and " +"BMI " + str(BMI) + "kg/m^2" )
  18.  
  19. if BMI > 60:
  20. print("\nYou are hyper obese see a doctor.")
  21. elif BMI > 30:
  22. print("\nYou are obese, please exercise and diet.")
  23. elif BMI >25:
  24. print("\nYou are overweight, please exercise and diet.")
  25. elif BMI >18.5:
  26. print("\nYou are normal, well done.")
  27. elif BMI > 15:
  28. print("\nYou are underweight, get your health checked.")
  29. else:
  30. print("\nIt seems your BMI is less than 15 you are very severly underweight, see a doctor.")
  31. print("bye")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement