1. 程式人生 > >Learn Python 010: Dictionary - Cinema Simulator

Learn Python 010: Dictionary - Cinema Simulator

cti [1] strip lease tar pri bsp cte logs

films = {
    ‘Finding Dory‘: [3, 5],
    ‘Bourne‘: [18, 7],
    ‘Tarzen‘: [15, 9],
    ‘Ghost Busters‘: [12, 5]
}

while True:
    choice = input(‘Please enter the selected film: ‘).title().strip()
    if choice in films:
        age = int(input(‘Please enter your age: ‘).strip())
        if age >= films[choice][0]:
            if films[choice][1] > 0:
                print(‘Enjoy.‘)
                films[choice][1] = films[choice][1] - 1
            else:
                print(‘Sorry, we are sold out.‘)
        else:
            print("Sorry, you are too young to watch the film.")

    else:
        print(‘Sorry, we do not have this film.‘)

Learn Python 010: Dictionary - Cinema Simulator