시작하기무료로 시작하기

elif로 더 세밀한 맞춤 설정하기

침실도 둘러볼 수 있습니다. 샘플 코드에는 room"bed"와 같은지 확인하는 elif 구문이 포함되어 있습니다. 이 경우 "looking around in the bedroom."이 출력됩니다.

이제 여러분 차례입니다! 두 번째 제어 구조에도 비슷한 내용을 추가하여 area의 다양한 값에 따른 메시지를 맞춤 설정해보세요.

이 연습은 강의의 일부입니다

중급 Python

강의 보기

연습 안내

area10보다 클 때 "medium size, nice!"가 출력되도록 두 번째 제어 구조에 elif를 추가하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Define variables
room = "bed"
area = 14.0

# if-elif-else construct for room
if room == "kit" :
    print("looking around in the kitchen.")
elif room == "bed":
    print("looking around in the bedroom.")
else :
    print("looking around elsewhere.")

# if-elif-else construct for area
if area > 15 :
    print("big place!")
else :
    print("pretty small.")
코드 편집 및 실행