day3-3 python (중첩 if 문과 elif문)

2023. 2. 22. 07:22개인적인 공부/Python

저번에 했던 if, else 문에서 

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

if height >= 120:
    print("You can ride the rollercoaster!")
else:
    print("Sorry, you have to grow taller before you can ride.")

중첩 if 문

중첩 if문

한번 더 선택의 갈림길이 주어진다.

# 중첩 if문
print("Welcome to the rollercoaster!")
height = int(input("What is your height in cm? "))
####################################################
if height >= 120:
    print("You can ride the rollercoaster!")
    age = int(input("What is your age? "))
    if age <= 18:
        print("Your pay is $7")
    else:
        print("Your pay is $12")
else:
    print("Sorry, you have to grow taller before you can ride.")

중첩 if 문
중첩 if 문과 elif

# 중첩 if문과 elif 문
print("Welcome to the rollercoaster!")
height = int(input("What is your height in cm? "))
####################################################
if height >= 120:
    print("You can ride the rollercoaster!")
    age = int(input("What is your age? "))
    if age < 12:
        print("Your pay is $5")
    elif age <=18:
        print("Your pay is $ 7")
    else:
        print("Your pay is $12")
else:
    print("Sorry, you have to grow taller before you can ride.")