Session 2024-2025
Central academy sr.
        secondary school
       Computer science project on
        (Train reservation system)
     Submitted by: Gyanwant singh
Submitted to: Mr. mohd yusuf
Class – XII             Sec : E
Roll no. :
               Certificate
This is to certify that the project submitted
 by (Gyanwant singh) on the topic (Train
Reservation System) in the department of
Computer Science, Indira Nagar, Lucknow
 in the accordance with the specifications
            prescribed by CBSE.
Mr. Mohd. Yusuf               Mr. D.P. Singh
Project Coordinator               Principal
Dept of Computer Science
              external examiner
             acknowledgement
I would like to express my heartful gratitude to
my computer teacher, Mr. Mohd. Yusuf, who
gave me this opportunity to do this thought-
provoking project on the topic “Train
Reservation System” which enhanced my
knowledge.
I would also like to thank my parents and
friends who helped me in completing this file
on time. Without the guidance and help from
each of the above mentioned, this would not
have been possible
                              Submitted by:
                              Gyanwant singh
                   Introduction
Python and MySQL are a
Powerful combination for
Building robust and scalable
applications. Python, a versatile
programming language, offers
and a wide range of
functionalities and a clean syntax that promotes
readability and ease of use. MySQL, a popular open-
source relational database management system, provides
a robust and efficient solutions for storing, organizing,
and
                   retrieving structured data. By
                   integrating python with MySQL
                   using libraries like MySQL
                   connector/python, developers can
                   leverage python’s flexibility and
MySQL’s reliability to create dynamic applications with
database functionality. This combination enables
seamless data management, efficient queries, and the
ability to handle large volumes of data, making it a
popular choice for web development, data analysis, and
various other applications.
 Python code
 Password – admin
from pickle import load,dump
import time
import random
import os
class tickets:
  def init__(self):
     self.no_ofac1stclass=0
     self.totaf=0
     self.no_ofac2ndclass=0
     self.no_ofac3rdclass=0
     self.no_ofsleeper=0
     self.no_oftickets=0
     self.name=””
     self.age=””
     self.resno=0
     self.status=””
  def ret(self):
     return(self.resno)
  def retname(self):
   return(self.name)
 def display(self):
   f=0
   finI=open(“tickets.dat”,”rb”)
   if not finI:
      print(“ERROR”)
###XXXXXXXXXXX
   Else:
      print
      n=int(input(“ENTER PNR NUMBER :”))
      print(“\n\n”)
      print(“FETCHING DATA…”.center(80))
      time.sleep(I)
      print
      print(“PLEASE WAIT…!!”.center(80))
      time.sleep(I)
      os.system(‘cls’)
  try:
     while True:
           tick=load(finI)
           if(n==tick.ret()):
              f=I
              print(“=”*80)
              print(“PNR STATUS”.center(80))
              print(“=”*80)
            print
            print(“PASSENGER’S NAME :”,tick.name)
            print
            print(“PASSENGERS’S AGE :”,tick.age)
            print
            print(“PNR NO :”,tick.resno)
            print
          ###XXXXXXXX
            print(“STATUS :”,tick.status)
            print
            print(“NO OF SEATS BOOKED :”,tick.no_oftickets)
            print
          else:
            pass
    finl.close()
    if(f==0):
          print
          print(“WRONG PNR NUMBER. :!!”)
          return
  except:
     pass
def pending(self):
  self.status=”WAITING LIST”
  print(“PNR NUMBER :”,self.resno)
  print
  time.sleep(1.2)
  print(“STATUS= “,self.status)
  print
  print(“NO OF SEATS BOOKED :”,self.no_oftickets)
  print
def confirmation (self):
  self.status=”CONFIRMED”
  print(“PNR NUMBER :”,self.resno)
  print
  time.sleep(1.5)
###XXXXXXXXXX
  print (“STATUS =”,self.status)
  print
def cancellation (self):
  z=0
  f=0
  fin=open(“tickets.dat”,”rb”)
  fout=open(“temp.dat”,”ab”)
  print
  r=int(input(“ENTER PNR NUMER :”))
  try:
      while(True):
          tick=load(fin)
          z=tick.ret()
          if(z!=r):
              dump(tick,fout)
          elif(z==r):
              f=1
  except:
             pass
  fin.close()
  fout.close()
  os.remove(“tickets.dat”)
  os.rename(“temp.dat”,”tickets.dat”)
  if(f==0):
     print
###XXXXXXXXXX
     print(“NO SUCH RESERVATION NUMBER FOUND”)
     print
     time.sleep(2)
     os.system(‘cls’)
  else:
     print
     print(“TICKET CANCELLED”)
     print
def reservation(self):
   trainno=int(input(“ENTER THE TRAIN NO:”))
tr=train()