day 3-1 python (if/else 및 조건 연산자를 통한 흐름 제어)

2023. 2. 21. 23:40개인적인 공부/Python

예시

print("Welcome to the rollercoaster!")
height = int(input("What is your height in cm? "))

if height > 120: # 만약에 120 보다 크다면
    print("You can ride the rollercoaster!")
else:
    print("Sorry, you have to grow taller before you can ride.")

결과

ㅇㅋ

결과1

120은 포함되지 않는다.

120cm 도 탈수 있게 하려면?

if height > 119:
################ 또는
if height >= 120:

이것을 비교 연산자라고 한다.

Operator Meaning
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
== Equal to
!= Not equal to

= Equal 1개는값을 변수에 지정한다.

height = int(input("What is your height in cm? "))

#######################################################
int(input("What is your height in cm? ")) <= 이 값을

height <= 이 변수로 지정해준다

== Equal 2개는 Check Equality

if height == 120:

# 왼쪽에 있는 값이 오른쪽에 있는 값과 같은지 확인하는것
# Check Equality

if 구문은 True or False

틀렸다고 알려준다.