나는 이렇게 학습한다/Algorithm & SQL

Calculate BMI

daco2020 2022. 7. 25. 20:02
반응형

Write function bmi that calculates body mass index (bmi = weight / height2).

if bmi <= 18.5 return "Underweight"

if bmi <= 25.0 return "Normal"

if bmi <= 30.0 return "Overweight"

if bmi > 30 return "Obese"

 

Solution:

def bmi(weight, height):
    bmi = weight/(height**2)
    return (bmi > 30 and "Obese") \
        or (bmi > 25 and "Overweight") \
        or (bmi > 18.5 and "Normal") \
        or "Underweight"

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

Simple Fun #176: Reverse Letter  (0) 2022.07.27
Money, Money, Money  (0) 2022.07.26
Check the exam  (0) 2022.07.24
What is between?  (0) 2022.07.24
Replace With Alphabet Position  (0) 2022.07.22