Write function bmi that calculates body mass index (bmi = weight / height ^ 2).


if bmi <= 18.5 return "Underweight"

if bmi <= 25.0 return "Normal"

if bmi <= 30.0 return "Overweight"

if bmi > 30 return "Obese"

Difficulty: EASY
Tags: Fundamentals

Starter code:
def bmi(weight, height):
	

Solutions:
def bmi(weight, height):
	bmi = weight / height ** 2
	if bmi <= 18.5:
		return 'Underweight'
	elif bmi <= 25:
		return 'Normal'
	elif bmi <= 30:
		return 'Overweight'
	else:
		return 'Obese'


def bmi(weight, height):
	b = weight / height ** 2
	return ['Underweight', 'Normal', 'Overweight', 'Obese'][(b > 30) + (b > 25) + (b > 18.5)]


def bmi(weight, height):
	youfat = weight / (height * height)
	if youfat <= 18.5:
		return 'Underweight'
	elif youfat <= 25.0:
		return 'Normal'
	elif youfat <= 30.0:
		return 'Overweight'
	else:
		return 'Obese'


def bmi(weight, height):
	bmeye = weight / height ** 2
	if bmeye <= 18.5:
		return 'Underweight'
	elif bmeye <= 25.0:
		return 'Normal'
	elif bmeye <= 30.0:
		return 'Overweight'
	elif bmeye > 30:
		return 'Obese'


def bmi(weight, height):
	index = weight / (height * height)
	if index <= 18.5:
		return 'Underweight'
	if index <= 25.0:
		return 'Normal'
	if index <= 30.0:
		return 'Overweight'
	if index > 30:
		return 'Obese'


bmi = lambda w, h: (lambda b=w / h ** 2: ['Underweight', 'Normal', 'Overweight', 'Obese'][(18.5 < b) + (25 < b) + (30 < b)])()


def bmi(weight, height):
	result = weight / height / height
	return 'Underweight Normal Overweight Obese'.split()[(result > 18.5) + (result > 25.0) + (result > 30.0)]


def bmi(weight, height):
	BMI = weight / (height * height)
	return 'Underweight' if BMI <= 18.5 else 'Normal' if BMI <= 25.0 else 'Overweight' if BMI <= 30.0 else 'Obese'


bmi = lambda w, h: next((s for (s, t) in zip('Obese Overweight Normal Underweight'.split(), (30, 25, 18.5, 0)) if w / h / h > t))


def bmi(w, h):
	x = w / h ** 2
	if x <= 18.5:
		return 'Underweight'
	elif 18.5 < x <= 25.0:
		return 'Normal'
	elif 25.0 < x <= 30.0:
		return 'Overweight'
	elif x > 30.0:
		return 'Obese'


def bmi(weight, height):
	BMI = weight / height ** 2
	if int(BMI) < 18.5:
		results = 'Underweight'
	elif int(BMI) < 25.0:
		results = 'Normal'
	elif int(BMI) < 30.0:
		results = 'Overweight'
	else:
		results = 'Obese'
	return results


def bmi(w, h):
	bmi = w / h ** 2
	if bmi <= 18.5:
		return 'Underweight'
	elif bmi <= 25:
		return 'Normal'
	elif bmi <= 30:
		return 'Overweight'
	else:
		return 'Obese'


def bmi(weight, height):
	bmi = weight / pow(height, 2)
	if bmi > 30:
		result = 'Obese'
	elif bmi <= 30.0 and bmi > 25.0:
		result = 'Overweight'
	elif bmi <= 25.0 and bmi > 18.5:
		result = 'Normal'
	else:
		result = 'Underweight'
	return result


def bmi(weight, height):
	bmi_val = weight / height ** 2
	return get_weight_class(bmi_val)

def get_weight_class(bmi_val):
	bmi_ranges = [(0, 18.5), (18.5, 25), (25, 30), (30, float('inf'))]
	weight_classes = {(0, 18.5): 'Underweight', (18.5, 25): 'Normal', (25, 30): 'Overweight', (30, float('inf')): 'Obese'}
	start = 0
	end = len(bmi_ranges) - 1
	while not start > end:
		mid_i = start + abs(end - start) // 2
		(range_start, range_end) = bmi_ranges[mid_i]
		if range_start < bmi_val <= range_end:
			return weight_classes[range_start, range_end]
		elif bmi_val <= range_start:
			end = mid_i - 1
		elif bmi_val > range_end:
			start = mid_i + 1
	raise ValueError('BMI value out of range.')


def bmi(weight, height):
	bmi = weight / height ** 2
	arr = 'Underweight Normal Overweight Obese'.split()
	return arr[(bmi > 18.5) + (bmi > 25) + (bmi > 30)]


def bmi(weight, height):
	bmi = weight / height ** 2
	return ['Underweight', 'Normal', 'Overweight', 'Obese'][int(bmi > 18.5) + int(bmi > 25.0) + int(bmi > 30.0)]


def bmi(weight, height):
	bm = weight / height ** 2.0
	for (val, outp) in zip([18.5, 25, 30], ['Underweight', 'Normal', 'Overweight']):
		if bm <= val:
			return outp
	return 'Obese'


a = lambda w, h: w / h ** 2
bmi = lambda w, h: 'Underweight' if a(w, h) <= 18.5 else 'Normal' if a(w, h) <= 25 else 'Overweight' if a(w, h) <= 30 else 'Obese'


bmi = lambda w, h: (lambda b: 'Underweight' if b <= 18.5 else 'Normal' if b <= 25.0 else 'Overweight' if b <= 30.0 else 'Obese')(w / h / h)


def bmi(weight, height):
	scale = {18.5: 'Underweight', 25.0: 'Normal', 30.0: 'Overweight'}
	x = weight / height / height
	for (bmi_class, label) in scale.items():
		if x < bmi_class:
			return label
	return 'Obese'


def bmi(weight, height):
	bm = weight / height ** 2
	if bm <= 18.5:
		return 'Underweight'
	if bm <= 25.0:
		return 'Normal'
	if bm <= 30.0:
		return 'Overweight'
	return 'Obese'


def bmi(weight, height):
	bmi = weight / height ** 2
	for (i, limit) in enumerate((18.5, 25, 30)):
		if bmi <= limit:
			return ('Underweight', 'Normal', 'Overweight')[i]
	else:
		return 'Obese'


def bmi(weight, height):
	abmi = weight / (height * height)
	if abmi <= 18.5:
		return 'Underweight'
	elif 18.5 < abmi <= 25.0:
		return 'Normal'
	elif 25.0 < abmi <= 30.0:
		return 'Overweight'
	elif 30.0 < abmi:
		return 'Obese'


def bmi(weight, height):
	a = weight / height ** 2
	if a > 30:
		return 'Obese'
	if a >= 25:
		return 'Overweight'
	if a >= 18.5:
		return 'Normal'
	return 'Underweight'


def bmi(weight, height):
	bmi_i = weight / height ** 2
	if bmi_i <= 18.8:
		return 'Underweight'
	if bmi_i <= 25.0:
		return 'Normal'
	if bmi_i <= 30.0:
		return 'Overweight'
	if bmi_i > 30:
		return 'Obese'


def bmi(w, h):
	s = w / h ** 2
	if s <= 18.5:
		return 'Underweight'
	if s <= 25:
		return 'Normal'
	if s <= 30:
		return 'Overweight'
	return 'Obese'


def bmi(weight, height):
	a = float(weight)
	b = float(height)
	b_m_i = a / b ** 2
	if b_m_i <= 18.5:
		return 'Underweight'
	if b_m_i <= 25.0:
		return 'Normal'
	if b_m_i <= 30.0:
		return 'Overweight'
	if b_m_i > 30:
		return 'Obese'


def bmi(weight, height):
	text = ['Overweight', 'Normal', 'Underweight', 'Obese']
	bmi = weight / height ** 2
	print(bmi)
	index = bool(bmi <= 18.5) + bool(bmi <= 25) + bool(bmi <= 30)
	print(bool(bmi <= 18.5), bool(bmi <= 25), bool(bmi <= 30), bool(bmi > 30))
	print(index)
	return text[index - 1]


def bmi(weight, height):
	beem = round(weight / height ** 2, 1)
	print(beem)
	if 18.5 >= beem:
		return 'Underweight'
	elif 25.0 >= beem > 18.5:
		return 'Normal'
	elif 30.0 >= beem > 18.5:
		return 'Overweight'
	else:
		return 'Obese'


def bmi(w, h):
	b = w / (h * h)
	if b <= 18.5:
		return 'Underweight'
	if b <= 25.0:
		return 'Normal'
	if b <= 30.0:
		return 'Overweight'
	if b > 30:
		return 'Obese'


def bmi(w, h):
	p = round(w // h // h, 1)
	return 'Underweight' if p <= 18.5 else 'Normal' if p <= 25.0 else 'Overweight' if p <= 30 else 'Obese'


def bmi(weight, height):
	a = weight / height ** 2
	if a <= 18.5:
		return 'Underweight'
	elif a <= 25.0:
		return 'Normal'
	elif a <= 30.0:
		return 'Overweight'
	elif a > 30:
		return 'Obese'
	return 'You are Grasshopper'


def bmi(weight, height):
	bmi = weight / height ** 2
	if bmi <= 18.5:
		return 'Underweight'
	elif bmi <= 25.0:
		return 'Normal'
	elif bmi <= 30.0:
		return 'Overweight'
	elif bmi > 30.0:
		return 'Obese'
	else:
		print('wrong input')


def bmi(weight, height):
	bmi = weight / height ** 2
	print(bmi)
	if bmi <= 18.5:
		result = 'Underweight'
	elif bmi <= 25:
		result = 'Normal'
	elif bmi <= 30:
		result = 'Overweight'
	elif bmi > 30:
		result = 'Obese'
	return result


def bmi(weight, height):
	b = weight / (height * height)
	health = {18.5: 'Underweight', 25.0: 'Normal', 30.0: 'Overweight'}
	for i in list(health.keys()):
		if b <= i:
			return health[i]
	return 'Obese'


def bmi(weight, height):
	bmi = weight * 10 // height ** 2
	if bmi in range(185):
		return 'Underweight'
	elif bmi in range(185, 250):
		return 'Normal'
	elif bmi in range(250, 300):
		return 'Overweight'
	elif bmi > 300:
		return 'Obese'


def bmi(weight, height):
	stages_of_life = ['Underweight', 'Normal', 'Overweight', 'Obese']
	BMI = weight / height ** 2
	pointer = 0 if BMI <= 18.5 else 1 if BMI <= 25 else 2 if BMI <= 30 else 3
	return stages_of_life[pointer]