본문 바로가기

여러가지/Python

Day 3 - 조건문 if, 관계연산자, 내장함수 count()

● 학습 내용

 

1) 조건문 if

a. if - else

b. if - elif - else

 

ex) 윤년 계산

year = int(input("This Year: "))

if year % 4 == 0:
  if year % 100 == 0:
    if year % 400 == 0:
      print("Leap year")
    else:
      print("Not leap year")
  else:
    print("Leap year")
else:
  print("Not leap year")

 

ex) 피자 주문

https://github.com/yooyijun15/Python/tree/main/Day3

=> 관련 없는 조건이라면 따로 빼서 작성하는 것이 가독성 좋고 간결하다.

 

2) 관계연산자

- and, or, not

 

(+)

print(''' <-  -> ''')

print('You\'re idea')

input().lower()

 

(연애 이름 궁합)

● GIT URL : https://github.com/yooyijun15/Python/tree/main/Day3

# count(): 포함된 문자 카운트하는 내장 함수