day 3-6 python (다중 연속 if 문)
2023. 2. 22. 21:09ㆍ개인적인 공부/Python
if/elif/else | Multiple if |
if condition1: do A elif condition2: do B else: do C |
if condition1: do A if condition2: do B if condition3: do C |
A, B, C 중 어느 하나만 수행함 | A,B,C 세가지 조건을 확인 후 모두 참이라면 A,B,C가 작동 |
# 다중 연속 if문
print("Welcome to the rollercoaster!")
height = int(input("What is your height in cm? "))
####################################################
bill = 0
if height >= 120:
print("You can ride the rollercoaster!")
age = int(input("What is your age? "))
if age < 12:
bill = 5
print("Child tickets are $5")
elif age <=18:
bill = 7
print("Youth tickets are is $ 7")
else:
bill =12
print("Adult tickets are $12")
wants_photo = input("Do you want a photo take? Y or N. ")
if wants_photo == "Y":
bill +=3
print(f"Your final bill is ${bill}")
else:
print("Sorry, you have to grow taller before you can ride.")
'개인적인 공부 > Python' 카테고리의 다른 글
day 3-8 python (논리 연산자) (0) | 2023.02.22 |
---|---|
day 3-7 python (피자주문) (0) | 2023.02.22 |
day 3-5 python (윤년, Leap Year) (0) | 2023.02.22 |
day 3-4 (BMI 2.0 Exercise) (0) | 2023.02.22 |
day3-3 python (중첩 if 문과 elif문) (0) | 2023.02.22 |