이제 파이썬을 입문하는 학생인데 질문입습니다.
조회수 93회
def std_weight(height, gender) :
if gender == 1 :
weight = height * height * 22
print("키 {0} 남자의 표준 체중은 {1}입니다.".format(height, float(round(weight,2))))
elif gender == 2 :
weight = height * height * 21
print("키 {0} 여자의 표준 체중은 {1}입니다.".format(height, float(round(weight,2))))
print("표준 체중을 구하는 프로그램\n")
height = input("키를 입력하시오 : ")
gender = input("성별을 입력하시오(남자:1, 여자:2) : ")
std_weight(height, gender)
이대로 실행시키면 바로 종료가 되는데 어떤 부분에서 수정을 해야할까요?
1 답변
-
다음 코드를 실행해보시고 어느 부분에서 문제가 있는지 제가 어떻게 확인했는지에 대해 살펴보세요.
다른 식으로 수정해야 하지만 무엇이 문제인지 어떻게 확인하는지 알려드리기 위해 다음 코드를 올립니다.
def std_weight(height, gender) : print(gender) print(type(gender)) print(height) print(type(height)) height = int(height) gender = int(gender) if gender == 1 : print(1) weight = height * height * 22 print(weight) print("키 {0} 남자의 표준 체중은 {1}입니다.".format(height, float(round(weight,2)))) elif gender == 2 : print(2) print(type(height)) weight = height * height * 21 print(weight) print("키 {0} 여자의 표준 체중은 {1}입니다.".format(height, float(round(weight,2)))) print("표준 체중을 구하는 프로그램\n") height = input("키를 입력하시오 : ") gender = input("성별을 입력하시오(남자:1, 여자:2) : ") std_weight(height, gender)
댓글 입력