Fundamentals 10 min read

Python Movie Ticket Booking System with Seat Selection and Film Selector

This article presents a complete Python console application that demonstrates how to build a movie ticket booking system, including data structures for film information, a seat‑booking class with interactive reservation methods, a film‑selection interface, and a controller that ties everything together, accompanied by full source code listings.

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 introduces a Python‑based movie ticket booking system, showing the overall effect of the program and providing a visual diagram of its structure.

Effect Display

Through Python, a movie ticket reservation system is implemented, with sample output illustrating the booking process.

Overall Structure Diagram

Code Breakdown

3.1 infos.py

infos = [
  {
    'name': '泰坦尼克号',
    'symbol': '\n+==================== 泰坦尼克号 =====================+\n  ▄▄▄▄▪   ▄▄▄▄  ▄▄▄·   ▐ ▄ ▪      ▄· \n  •██   ██  •██   ▐█ ▀█  •█▌▐█  ██  ▐█ ▌▪\n  ▐█.▪ ▐█·  ▐█. ▪▄█▀▀█  ▐█▐▐▌  ▐█· ██ ▄\n  ▐█▌ ·▐█▌  ▐█▌· ▐█ ▪▐▌ ██▐█▌  ▐█▌ ▐███▌\n  ▀▀▀  ▀▀▀  ▀▀▀   ▀  ▀  ▀▀ █  ▪▀▀▀ ·▀▀▀ \n+===================== Titanic =====================+\n',
    'seats': [[
      '○','○','○','○','○','○','○','○'],
      ['○','○','○','○','●','○','○','●'],
      ['○','○','●','○','●','○','○','○'],
      ['○','○','●','○','○','○','○','●'],
      ['○','○','●','○','○','○','●','○'],
      ['●','○','○','○','●','●','●','●']
    ]
  },
  {
    'name': '雨人',
    'symbol': "...",
    'seats': [[...]]
  },
  ...
]

3.2 seat_book.py

import time

class SeatBooking:
  # 展示所有座位的预订信息
  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.3 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

3.4 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('+============================+')

# 实例化 Controller 类
s = Controller(infos)

The article concludes with a call‑to‑action encouraging readers to scan a QR code to receive free Python learning resources and provides links to related Python tutorials.

pythonProgramming TutorialConsole Applicationmovie-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.