Backend Development 10 min read

Python Movie Ticket Booking System with Seat Selection and Film Selector

This tutorial walks through building a Python command‑line movie ticket reservation system, covering data structures for film information, seat‑booking class design, user interaction for selecting seats or the front‑most available seat, and a controller that ties the film selector and seat booking together.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Python Movie Ticket Booking System with Seat Selection and Film Selector

The article presents a complete Python command‑line movie ticket reservation system, illustrating how to organize film data, display seat maps, and handle user interactions for booking seats.

1. Data Structure (infos.py)

infos = [
  {
    'name': '泰坦尼克号',
    'symbol': '+==================== 泰坦尼克号 =====================+\n  ... (ASCII art) ...',
    'seats': [
        ['○','○','○','○','○','○','○','○'],
        ['○','○','○','○','●','○','○','●'],
        ['○','○','●','○','●','○','○','○'],
        ['○','○','●','○','○','○','○','●'],
        ['○','○','●','○','○','○','●','○'],
        ['●','○','○','○','●','●','●','●']
    ]
  },
  {... other movies ...}
]

2. Seat Booking Logic (seat_book.py)

import time

class SeatBooking:
    # Show all seats' booking status
    def check_bookings(self, seats):
        print("正在为您查询该场次电影的预订状态...")
        time.sleep(0.7)
        print('从上到下为 1~6 排,从左至右为 1~8 座')
        print("======================")
        for row in seats:
            time.sleep(0.1)
            print('  '.join(row))
        print("======================")
        time.sleep(0.7)

    def get_row(self):
        input_row = input("预订第几排的座位呢?请输入 1~6 之间的数字")
        valid_row = [str(i+1) for i in range(6)]
        while input_row not in valid_row:
            input_row = input('没有按要求输入哦,请输入 1~6 之间的数字')
        return int(input_row) - 1

    def get_col(self):
        input_column = input('预订这一排的第几座呢?请输入 1~8 之间的数字')
        valid_column = [str(i+1) for i in range(8)]
        while input_column not in valid_column:
            input_column = input('没有按要求输入哦,请输入 1~8 之间的数字')
        return int(input_column) - 1

    def book_seat(self, seats):
        while True:
            row = self.get_row()
            column = self.get_col()
            if seats[row][column] == '○':
                print('正在为您预订指定座位...')
                time.sleep(0.7)
                seats[row][column] = '●'
                print('预订成功!座位号:{}排{}座'.format(row+1, column+1))
                break
            else:
                print('这个座位已经被预订了哦,试试别的吧')
                time.sleep(0.7)

    def book_seat_at_front(self, seats):
        print('正在为您预订最靠前的座位...')
        time.sleep(0.7)
        for row in range(6):
            for column in range(8):
                if seats[row][column] == '○':
                    seats[row][column] = '●'
                    print('预订成功!座位号:{}排{}座'.format(row+1, column+1))
                    return
        print('非常抱歉🥺,所有座位都被订满了,无法为您保留座位')

3. Film Selection Logic (film_selector.py)

import time

class FilmSelector:
    def display_options(self, films):
        print('今日影院排片列表:')
        print('+================+')
        for i in range(len(films)):
            print('{} - {}'.format(i+1, films[i]['name']))
            time.sleep(0.2)
        print('x - 退出')
        print('+================+')
        time.sleep(0.7)

    def get_choice(self, films):
        valid_choice = [str(i+1) for i in range(len(films))]
        valid_choice.append('x')
        choice = input('你的选择是?')
        while choice not in valid_choice:
            choice = input('没有按照要求输入哦,请重新输入')
        return choice

4. Main Controller (main.py)

import time
from infos import infos
from film_selector import FilmSelector
from seat_booking import SeatBooking

class Controller:
    def __init__(self, infos):
        self.films = infos
        self.welcome()
        self.choose_film()
        if self.choice != 'x':
            self.choose_seat()
        self.bye()

    def choose_film(self):
        selector = FilmSelector()
        selector.display_options(self.films)
        self.choice = selector.get_choice(self.films)

    def choose_seat(self):
        film = self.films[int(self.choice)-1]
        name = film['name']
        seats_list = film['seats']
        symbol = film['symbol']
        print('正在为您预订电影《{}》的座位...'.format(name))
        time.sleep(0.7)
        print(symbol)
        time.sleep(0.7)
        print('支持的座位预订方式如下:')
        time.sleep(0.7)
        print('+==========================+')
        print('1 - 指定行列号预定座位')
        print('2 - 给我预订一个最靠前的座位!')
        print('+==========================+')
        time.sleep(0.7)
        method = input('请选择座位预订方式')
        valid_method = ['1','2']
        while method not in valid_method:
            method = input('没有按照要求输入哦,请重新输入')
        booking = SeatBooking()
        booking.check_bookings(seats_list)
        if method == '1':
            booking.book_seat(seats_list)
        else:
            booking.book_seat_at_front(seats_list)

    def welcome(self):
        print('+============================+')
        print('+      欢迎来到时光电影院      +')
        print('+============================+')
        print('')
        time.sleep(0.7)

    def bye(self):
        print('')
        time.sleep(0.7)
        print('+============================+')
        print('+    已经退出系统,下次见!👋    +')
        print('+============================+')

# Instantiate the controller
s = Controller(infos)

The guide also includes promotional messages and QR‑code images for a free Python public course, but the core of the article is the step‑by‑step implementation of the movie ticket system.

command-lineTutorialclass-designmovie-ticketseat-booking
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.