개인적인 공부/Python

day 3-6 python (다중 연속 if 문)

karatejin 2023. 2. 22. 21:09
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.")