Python: 체지방 계산기 심화 (BMI)

Frigate·2022년 5월 24일
0

Python 기초문법

목록 보기
22/27

Instructions

  1. 사용자의 키와 몸무게에 기반해서 BMI를 계산 및 해석해주는 프로그램 만드시오

  • BMI값은 아래의 BMI 변수들에 의해 결정됌


** BMI값이 18.5 아래면, 저체중이다

** BMI값이 18.5 넘고, 25 아래면, 정상체중

** BMI값이 25 넘고 35 아래면, 비만

** BMI값이 35 넘어가면 고도비만

  • BMI는 사람 몸무게를 키의 제곱으로 나눠서 계산함

  • BMI값을 가장 가까운 정수형으로 나타내시오 (뜻: 반올림해라;)

Example Input

weight = 85
height = 1.75

Example Output

85 ÷ (1.75 x 1.75) = 27.755102040816325

Your BMI is 28, you are slightly overweight.

  • 해석 출력값은 아래중에서 나와야 함
"Your BMI is 18, you are underweight."
"Your BMI is 22, you have a normal weight."
"Your BMI is 28, you are slightly overweight."
"Your BMI is 33, you are obese."
"Your BMI is 40, you are clinically obese."

Try it

* 오답

⇒ 변수 bmi 데이터형을 명시 안해줬네..

Int형으로 명시해주면 코드 실행 잘돼는데

bmi 값은 근사한 정수형으로 나타내라는건 반올림하란 얘기다. int() 형변환 하라는 뜻이 아님.

# 🚨 Don't change the code below 👇
height = float(input("enter your height in m: "))
weight = float(input("enter your weight in kg: "))
# 🚨 Don't change the code above 👆

#Write your code below this line 👇
bmi = weight / height ** 2
if bmi <= 18.5 :
   print(f"your BMI is {bmi}, you are underweight.")
elif bmi > 18.5 :
   if bmi <= 25 :
      print(f"your BMI is {bmi}, they have a normal weight.")

elif bmi > 25 :
  if bmi <= 30 :
    print(f"your BMI is {bmi}, you are slightly overwight.")

elif bmi > 30 :
  if bmi <= 35 :
    print(f"your BMI is {bmi}, you are obese.")

else :
  print(f"your BMI is {bmi}, you are clinically obese.")

* 답1

# 🚨 Don't change the code below 👇
height = float(input("enter your height in m: "))
weight = float(input("enter your weight in kg: "))
# 🚨 Don't change the code above 👆

#Write your code below this line 👇
bmi = round(weight / height ** 2)    # 반올림해서 소숫점 없는 정수형으로 나타내어진다
if bmi <= 18.5 :
   print(f"your BMI is {bmi}, you are underweight.")
elif bmi > 18.5 :
   if bmi <= 25 :
      print(f"your BMI is {bmi}, they have a normal weight.")

elif bmi > 25 :
  if bmi <= 30 :
    print(f"your BMI is {bmi}, you are slightly overwight.")

elif bmi > 30 :
  if bmi <= 35 :
    print(f"your BMI is {bmi}, you are obese.")

else :
  print(f"your BMI is {bmi}, you are clinically obese.")

* 오답

bmi해석 메시지 출력 조건이 아래인데, 영어해석 실수를 했음

Under 18.5 they are underweight

Over 18.5 but below 25 they have a normal weight

Over 25 but below 30 they are slightly overweight

Over 30 but below 35 they are obese

Above 35 they are clinically obese.

Under 18.5 뜻: 18.5 미만

Over 18.5 뜻: 18.5 이상 (즉, 18.5를 포함해서 Up 이라는 것)

# 🚨 Don't change the code below 👇
height = float(input("enter your height in m: "))
weight = float(input("enter your weight in kg: "))
# 🚨 Don't change the code above 👆

#Write your code below this line 👇

bmi = round(weight / height ** 2)
if bmi < 18.5:
  print(f"Your BMI is {bmi}, you are underweight.")
elif bmi < 25:
  print(f"Your BMI is {bmi}, you have a normal weight.")
elif bmi < 30:
  print(f"Your BMI is {bmi}, you are slightly overweight.")
elif bmi < 35:
  print(f"Your BMI is {bmi}, you are obese.")
else:
  print(f"Your BMI is {bmi}, you are clinically obese.")

#유데미 #유데미코리아 #스타트위드유데미 #스터디윗미

profile
Swift

0개의 댓글