Python Basics - If Statement

Jayson Hwang·2022년 4월 27일
0

04. if(조건문)

어떠한 조건을 주고 이 조건에 맞는 상황을 수행하도록 하는 것


📌 04-1. if의 기본 구조

if 조건:
	실행 명령문
elif 조건2:
	실행 명령문
else:
	실행 명령문

if-else를 사용하여 코드를 작성하면, 조건을 만족(True)하면 if에 해당하는 부분을 수행하고, 만족하지 않으면 else부분을 수행


📌 04-2. if, elif, 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")
profile
"Your goals, Minus your doubts, Equal your reality"

0개의 댓글