Learn
Exam

Calculate BMI

Difficulty
STARTER

Problem

BMI (Body Mass Index) is a measure of body fat based on weight and height.
Given weight (kg) and height (m), write a function solution that calculates BMI and returns a status based on the result.

The BMI ranges and corresponding statuses are as follows:

  • Less than 18.5: Underweight
  • Between 18.5 and 23 (exclusive): Normal
  • Between 23 and 25 (exclusive): Overweight
  • 25 or above: Obese

Constraints

  • weight is a floating-point number between 30 and 100 inclusive. (unit: kg)
  • height is a floating-point number between 1.4 and 2.0 inclusive. (unit: m)

Test Case

Test Case Number weight height return
1 70.0 1.75 "Normal"
2 50.0 1.45 "Overweight"
3 85.0 1.80 "Obese"

Explanation for Test Case 1

  • When weight = 70.0 and height = 1.75, BMI = 70.0 / (1.75 * 1.75) ≈ 22.86, so return Normal.

Explanation for Test Case 2

  • When weight = 50.0 and height = 1.45, BMI = 50.0 / (1.45 * 1.45) ≈ 23.78, so return Overweight.

Explanation for Test Case 3

  • When weight = 85.0 and height = 1.80, BMI = 85.0 / (1.80 * 1.80) ≈ 26.23, so return Obese.