개발자 모드/파이썬(python)
파이썬(python) 조건문 if, in, not in
인생은직구
2021. 6. 11. 19:41
728x90
# chapter 04_01
# 파이썬 제어문
# if 실습
# 기본형식
print(type(True)) # 0이 아닌 수 , "abc" , [1,2,3], {1,2,3}....
print(type(False)) # 0, "", {},() ...
# 예제 1
if True:
print('Good')
if False:
print('Bad')
# 에제 2
if False:
print('Bad')
else:
print('Good')
# 관계 연산자
# >, >=, <, <=, ==, !=
x = 15
y = 10
# 양번이 같은 경우
print(x == y)
# 양번이 다를 경우
print(x != y)
# 왼쪽이 클때
print(x > y)
# 왼쪽이 크거나 같을때
print(x >= y)
# 오른쪽이 클때
print(x <= y)
# 오른쪽이 크거나 같을 때
print(x <= y)
city = ""
if city:
print("you are in")
else:
print("plz enter your city")
city2 = "seoul"
if city2:
print("you are in seoul")
else:
print("plz enter your city")
# 논리 연산자
# and, or, not
a = 75
b = 40
c= 10
print ( a > b and b > c ) # a > b > c
print(a > b or b > c)
print(not a > b)
print(not b > c)
print(not True)
print(not False)
print()
# 산술, 관계, 논리 우선순위
print( 3 + 12 > 7 + 3)
print(5 + 10 *3 > 7 + 3 * 20)
print(5 + 10 >3 and 7+3 ==10)
print(5 + 10 > 0 and not 7+3 ==10)
score1 = 90
score2 ='A'
if score1 >= 90 and score2 =='A' :
print('pass')
else:
print( 'Fail')
id1 ='vip'
id2 = 'admin'
grade ='platinum'
if id1 == 'vip' or id2 =='admin' :
print('관리자 입장')
if id1 == 'vip' or id2 =='platinum' :
print('최상위 관리자 입장')
# 예제
num = 70
if num >= 90:
print('A')
elif num >= 80:
print('B')
elif num >= 70:
print('C')
else:
print('과락')
# 중첩 조건문
grade ='A'
total = 95
if grade =='A' :
if total >= 90 :
print('100')
elif total >= 80 :
print('80')
else :
print('0')
else :
print('0')
# in, not in
q = [10, 20, 30]
w ={70, 80, 90 ,100}
print(15 in q)
print(20 in q)
print(70 not in w)
결과
[Command: python -u C:\python_basic\chapter04_01.py]
<class 'bool'>
<class 'bool'>
Good
Good
False
True
True
True
False
False
plz enter your city
you are in seoul
True
True
False
False
False
True
True
False
True
False
pass
관리자 입장
최상위 관리자 입장
C
100
False
True
False
[Finished in 0.141s]
728x90