어떠한 조건을 주고 이 조건에 맞는 상황을 수행하도록 하는 것
if 조건: 실행 명령문 elif 조건2: 실행 명령문 else: 실행 명령문
if-else를 사용하여 코드를 작성하면, 조건을 만족(True)하면 if에 해당하는 부분을 수행하고, 만족하지 않으면 else부분을 수행
<1>
weather = input("How is the weather today?")
if weather == "rain" or weather =="snow":
print("bring your umbrella")
elif weather == "fine dust":
print("bring the mask")
else:
print("You don't need to bring anything")
<2>
temp = int(input("how's the temperature?"))
if 30 <= temp:
print("Too hot")
elif 10 <= temp and temp < 30:
print("Nice for a walk")
elif 0 <= temp and temp < 10:
print("Bring your jacket")
else:
print("Too cold")