ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 9.if 조건문: 흐름제어
    공부합시다!/python 2023. 2. 1. 00:13
    728x90

    드디어 자료형을 넘어서 조건문으로 들어옵니다.

    제일 재밌는 부분이죠! 반드시 사용하는 부분이기도 하구요!

    즐기세요!

     

    # Python 흐름제어(제어문)
    
    print(type(True))
    print(type(False))
    
    # EX-1
    if True:
      print('Yes')
      
    # EX-2 
    if False:
      print('No')
    
    # EX-3 
    if False:
      print('No')
    else:
      print('No2')
      
    #관계 연산자
    # >, >=, <, <=, ==, !=
    
    a = 10
    b = 0
    
    print(a == b)
    print(a != b)
    print(a > b)
    print(a >= b)
    print(a < b)
    print(a <= b)
    
    # 참, 거짓의 종류(True, False)
    # 참 : "내용", [내용], (내용), {내용}, 1
    # 거짓 : "", [], (), {}, 0
    
    city = ""
    
    if city:
      print('>>>>True')
    else:
      print('>>>>>False')
      
    
    # 논리 연산자
    # and or not
    
    a = 100
    b = 60
    c = 15
    
    print('and : ', a > b and b > c)
    print('or : ', a > b or c > b)
    print('not : ', not a > b)
    print(not False)
    print(not True)
    
    
    # 산술, 관계, 논리 연산자
    # 산술 > 관계 > 논리 연산자
    
    print('EX-1 : ', 5 + 10 > 0 and not 7 + 3 == 10)
    
    score1 = 90
    score2 = 'A'
    
    if score1 >= 90 and score2 == 'A':
      print('합격')
    else:
      print('불합격')
      
    # 다중 조건문
    #num = int(input('점수를 입력하세요 : '))
    num = input('점수를 입력하세요 : ')
    num = int(num)
    
    if num >= 90:
      print('num 등급 a', num)
    elif num >= 80:
      print('num 등급 b', num )
    elif num >= 70:
      print('num 등급 c', num)
    else:
      print('꽝!')
      
    # 중첩 조건문
    age = int(input('나이를 입력하세요 : '))
    height = int(input('키를 입력하세요 :'))
    age = int(age)
    height = int(height)
    
    if age >= 20:
      if height >= 175:
        print('출입가능')
      elif height >= 160:
        print('출입 불가')
      else:
        print('지원불가')
    else:
      print('20세 이상 지원 가능')

     

     

     

     

     

    728x90

    '공부합시다! > python' 카테고리의 다른 글

    11.Function  (0) 2023.02.03
    10.for, while: 흐름제어  (0) 2023.02.02
    8.Set  (0) 2023.01.31
    7. Dictionary  (0) 2023.01.25
    6. Tuple  (0) 2023.01.20
Designed by Tistory.