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