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
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
'개인적인 공부 > Python' 카테고리의 다른 글
day3-3 python (중첩 if 문과 elif문) (0) | 2023.02.22 |
---|---|
day 3-2 python (Odd or Even Exercise)(홀수 또는 짝수) (0) | 2023.02.22 |
day 2-8 Python (팁 계산기 tip-Calculator) (0) | 2023.02.21 |
day 2-7 python (Life in Weeks Exercise) (0) | 2023.02.21 |
day2-6 python (숫자 처리 및 F-String) (0) | 2023.02.21 |