You are on page 1of 38

TOPIC:

RAILWAY RESERVATION SYSTEM

SESSION 2022-23

SUBMITTED BY: MANAV, KHUSHBU,


URMILA.
CLASS: XII A
INDEX

1. Certificate

2. Acknowledgements

3. Declaration

4. Aim

5. Coding with Screenshots

a. Requirements

b. Bibliography
CERTIFICATE
This is to certify
that Manav,
Khushbu,
Urmila
have successfully
completed this project
report entitled
“RAILWAY RESERVATION SYSTEM”
During the academic year 2022-2023
towards partial fulfillment of
C.S. Practical
Examination
conducted by CBSE.

Teacher’s Signature Principal’s Signature

External Invigilator’s Signature


ACKNOWLEDGEMENT
We take this opportunity to express our
profound gratitude and deep regards to our
subject teacher for his exemplary guidance,
monitoring and constant encouragement
throughout the course of this project.

The blessing, help and guidance given by


him time to shall carry us a long way in the
journey of life
on which we are about to embark.

- Manav, Khushbu, Urmila


DECLARATION
We hereby declare that the project
work entitled:

“RAILWAY RESERVATION SYSTEM”


Is prepared by us,
Manav
Khushbu
Urmila
Under the supervision of our
subject teacher “Mr.Bharat Katariya” for
the partial fulfillment of
AIM

Write a program using Python and MY-


SQL connectivity for Railway
Reservation
INTRODUCTION
This project introduces railway
reservation system. It explains how
reservation is being done in Indian
Railways. The step by step procedure
is explained. Proper comments have
been given at desired location to make
the project user friendly. Various
functions and structures are used to
make a complete use of this language;
this project is well versed with the
programming. Railway reservation can
easily accompany with the help of this.
ABOUT PYTHON

Python is a high level, object-oriented programming


language. It was developed in 1991 by Guido Van Rossum.
Its syntax is similar to the English Language and that is
why it enhances code readability. It uses indentation for
defining scopes of loops if-else construct, class, etc.

Python Logo -File Handling in Python

Python can be used to create server-side

applications. Python can help to do task

automation using scripting. Python is used to

create stand-alone applications.

Python is used in Big Data, data science,


Machine Learning……….

Actually, the list can go on and on. This defines the


power of Python as a programming language. Hence it
becomes very important to learn how to write to a file
using python and then read from the same file.
Python is an interpreted, object-oriented, high-level
programming language with dynamic semantics. Its high-
level built in data structures, combined with dynamic
typing and dynamic binding, make it very attractive for
Rapid Application Development, as well as for use as a
scripting or glue language to connect existing components
together.

Python's simple, easy to learn syntax emphasizes


readability and therefore reduces the cost of program
maintenance. Python supports modules and packages,
which encourages program modularity and code reuse.
The Python interpreter and the extensive standard
library are available in source or binary form without
charge for all major platforms, and can be freely
distributed.

Often, programmers fall in love with Python because of


the increased productivity it provides. Since there is no
compilation step, the edit-test-debug cycle is incredibly
fast. Debugging Python programs is easy: a bug or bad
input will never cause a segmentation fault. Instead,
when the interpreter discovers an error, it raises an
exception. When the program doesn't catch the
exception, the interpreter prints a stack trace. A source
level debugger allows inspection of local and global
variables, evaluation of arbitrary expressions, setting
breakpoints, stepping through the code a line at a time,
and so on.
The debugger is written in Python itself, testifying to
Python's introspective power.
On the other hand, often the quickest way to debug a
program is to add a few print statements to the source:
the fast edit-test- debug cycle makes this simple
approach very effective.
A recent survey established the Python language to be the
fifth most popular, behind JavaScript, SQL, Java, and C#.
According to the 2017 Stack Overflow survey, nearly 32%
of developers use it, and a further 20% want to do so. The
usage is up from 22% reported in the first Stack Overflow
survey, which ran in 2013.

The survey also reports Python to be the sixth most


loved language (behind Rust, Smalltalk, TypeScript,
Swift, and Go), and I think it s interesting to note that
Python is the top language that is both used and loved.
(the other languages that are loved are mostly aspirational,
for
example, TypeScript is used by just 9.5% of people,
while Rust and Smalltalk aren’t even on the scale).

There are more than 147,000 packages in the package


repository (colloquially known as the Cheese Shop),
which are what make it so versatile, and so popular. You
can use Python for everything from web development, to
data science and data visualisation, to games
development, and DevOps, without having to start at
ground zero and implement your own code for
everything.

With so many packages available, we are seeing, in


particular, a huge uptake in those used for AI and data
science projects.
Python is a super fun language which can brings a level of
excitement and ease to programming like no other language
can.
FILE HANDLING IN PYTHON

If you are working in a large software application where


they process a large number of data, then we cannot
expect those data to be stored in a variable as the
variables are volatile in nature.

Hence when are you about to handle such situations,


the role of files will come into the picture.

As files are non-volatile in nature, the data will be


stored permanently in a secondary device like Hard
Disk and using python we will handle these files in
our applications.

Python too supports file handling and allows users to


handle files i.e., to read and write files, along with many
other file handling options, to operate on files. The
concept of file handling has stretched over various other
languages, but the implementation is either complicated
or lengthy, but alike other concepts of Python, this
concept here is also easy and short. Python treats file
differently as text or binary and this is important. Each
line of code includes a sequence of characters and they
form text file.
Each line of a file is terminated with a special
character, called the EOL or End of Line characters like
comma {,} or newline character. It ends the current line
and tells the interpreter a new one has begun. Let s
start with Reading and Writing files.
Working of open () function:
We use open () function in Python to open a file in read
or write mode. As explained above, open ( ) will return a
file object. To return a file object we use open() function
along with two arguments, that accepts file name and
the mode, whether to read or write. So, the syntax being:
open(filename, mode). There are three kinds of mode,
that Python provides and how files can be opened:

“ r “, for reading.
“ w “, for writing.
“ a “, for appending.
“ r+ “, for both reading and writing

One must keep in mind that the mode argument is not


mandatory. If not passed, then Python will assume
it to be “r” by default.

There are also various other functions that help to


manipulate the files and its contents. One can explore
various other functions in Python Docs.
ABOUT MODULES

Modules refer to a file containing Python statements and


definitions. A file containing Python code, for e.g.:
example.py, is called a module and its module name would
be example.

We use modules to break down large programs into


small manageable and organized files. Furthermore,
modules provide reusability of code.

We can define our most used functions in a module and


import it, instead of copying their definitions into
different programs.

We can import the definitions inside a module to another


module or the interactive interpreter in Python.
We use the import keyword to do this.

Python has a ton of standard modules available.


Standard modules can be imported the same way as we
import our user- defined modules.

Some advantages of modules are:

1. Division of development
2. Increases readability of program
3. Programming errors can easily be detected
4. Allows reuse of code
5. Improves manageability
6. Collaboration in projects made efficient and easy.
ABOUT INDIAN RAILWAY

Indian Railways is the state-owned railway company of


India; it has a complete monopoly over the country's rail
transport. Indian Railways (IR) has one of the largest and
busiest rail networks in the world, transporting over 5
billion passengers and over 350 million tonnes of freight
annually. IR is also the world's largest commercial or
utility employer, having more than 1.6 million regular
employees on its payroll.

Railways were first introduced to India in 1853, and by


1947, the year of India's independence, it had grown to
forty-two rail systems. In 1951 the systems were
nationalised as one unit, to become one of the largest
networks in the world.
Indian Railways operates both long distances, as well as
suburban rail systems. It operates 8,702 passenger trains
and transports around five billion annually across twenty-
seven states and three union territories (Delhi,
Puducherry and Chandigarh). Sikkim is the only state not
connected. The Railway Budget deals with the induction
and improvement of existing trains and routes, the
modernisation and most importantly the tariff for freight
and passenger travel.

Due to the huge magnitude of the spread of IR, the system


cannot sustain without computers, which have programs
built for its smooth functioning. This project deals with the
Indian Railways and presents a system to digitize the
system.
CODING
MODULES USED
tickets.rv

def init ():


no ofac1stclass=0
totaf=0
no ofac2ndclass=0
no ofac3rdclass=0
no ofsleeper=0
no
oftickets=0
name=”
age=”
resno=
0
status=

def ret():
return(res
no) def
retname():
return(nam
e) def
display():
f=0
fin1=open(”tickets.dat”,”rb
”) if not fin1:
print (”ERROR”)
else:
print
n=int(input(”ENTER PNR NUMBER : ”))
print (”\n\n”)
print (”FETCHING DATA ...”.center(80))
time.sleep(1)
print
print('PLEASE
WAIT...!!'.center(80)) time.sleep(1)
os.system('cls
') try:
while True:
tick=load(fin 1)
if(n==tick.ret()):
f=1
print (”=”*80)
print(”PNR
STATUS”.center(80)) print
(”=”*80)
print
print (”PASSENGER'S NAME:”,tick.name)
print
print (”PASSENGER'S AGE :”,tick.age)
print
print (”PNR
NO :”,tick.resno) print
print (”STATUS :”,tick.status)
print
print (”NO OF SEATS BOOKED : ”,tick.no oftickets)
print
except:
pass
fin1.close(
) if(f==0):
print
print (”WRONG PNR NUMBER..!!”)
print
def
pending():
status=”WAITING LIST”
print (”PNR NUMBER :”,resno)
print
time.sleep( 1.2)
print (”STATUS = ”,status)
print
print (”NO OF SEATS BOOKED : ”,no oftickets)
print
def confirmation ():
status=”CONFIRMED”
print (”PNR NUMBER : ”,resno)
print
time.sleep( 1.5)
print (”STATUS = ”,status)
print
def
cancellation():
z=0
f=0
fin=open(”tickets.dat”,”rb”)
fout=open(”temp.dat”,”ab”)
print
r= int(input(”ENTER PNR NUMBER : ”))
try:
while(True):
tick=load(fin
) z=tick.ret()
if(z!=r):
dump(tick,fou
t) 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
print (”NO SUCH RESERVATION NUMBER FOUND”)
print
time.sleep(2)
os.system('cls
')
else:
print
print (”TICKET CANCELLED”)
print
def reservation():
trainno=int(input(”ENTER THE TRAIN NO:”))
z=0
f=0
fin2=open(”trdetails.dat”)
fin2.seek(0)
if not fin2:
print (”ERROR”)
else:
try:
while True:
tr=load(fin2)
z=tr.gettrainno()
n=tr.gettrainname
() if (trainno==z):
print
print (”TRAIN NAME IS : ”,n)
f=1
prin
t
print (”-”*80)
no ofaclst=tr.getno ofaclstclass()
no ofac2nd=tr.getno
ofac2ndclass() no
ofac3rd=tr.getno ofac3rdclass()
no ofsleeper=tr.getno ofsleeper()
if(f== 1):
foutl=open(”tickets.dat”,”ab
”) print
name=input
print(”ENTER THE PASSENGER'S NAME ”)
print
age=int(input(”PASSENGER'S AGE : ”))
print
print (”\t\t SELECT A CLASS YOU WOULD LIKE TO TRAVEL IN :- ”)
print (”1.AC FIRST CLASS”)
print
print (”2.AC SECOND CLASS”)
print
print (”3.AC THIRD CLASS”)
print
print (”4.SLEEPER CLASS”)
print
c=int(input(”\t\t\tENTER YOUR CHOICE =
”)) os.system('cls')
amt1=0
if(c==1):
no oftickets=int(input(”ENTER NO OF FIRST CLASS AC 5SEATS TO BE BOOKED : ”))
i=1
while(i<=no oftickets):
totaf=totaf+ 1
amtl=1000*no
oftickets i=i+1
print
print(”PROCESSING. .”,time.sleep(0.5))
print (”.”,time.sleep(0.3))
print('.')
time.sleep(2)
os.system('cls
')
print (”TOTAL AMOUNT TO BE PAID = ”,amtl)
resno=int(random.randint(1000,25
46)) x=no ofac1st-totaf
print
if(x>0):
confirmation
()
dump(fout1)
break
else:
pending()
dump(tick,foutl
) break
elif(c==2):
no oftickets=int(input(”ENTER NO OF SECOND CLASS AC SEATS TO BE BOOKED : ”))
i=1
while(i<=no oftickets):
totaf=totaf+ 1
amtl=900*no
oftickets i=i+1
print
print (”PROCESSING. .”,time.sleep(0.5))
print (”.”,time.sleep(0.3))
print
('.',time.sleep(2))
os.system('cls')
print (”TOTAL AMOUNT TO BE PAID = ”,amtl)
resno=random.randint(1000,25
46) x=no ofac2nd-totaf
print
if(x>0):
confirmation
()
dump(fout1)
break
else:
pending()
dump(tick,foutl
) break
elif(c==3):
no oftickets=int(input(”ENTER NO OF THIRD CLASS AC SEATS TO BE BOOKED : ”)) i=1
while(i<=no oftickets):
totaf=totaf+ 1
amtl=800*no
oftickets i=i+1
print
print (”PROCESSING. .”,time.sleep(0.5))
print (”.”,time.sleep(0.3))
print ('.')
time.sleep(2)
os.system('cls
')
print (”TOTAL AMOUNT TO BE PAID = ”,amtl)
resno=random.randint(1000,25
46) x=no ofac3rd-totaf
print
if(x>0):
confirmation
()
dump(fout1)
break
else:
pending()
dump(tick,foutl
) break
elif(c==4):
no oftickets=int(input(”ENTER NO OF SLEEPER CLASS SEATS TO BE BOOKED : ”)) i=1
while(i<=no oftickets):
totaf=totaf+ 1
amtl=550*no
oftickets i=i+1
print
print (”PROCESSING. .”,time.sleep(0.5))
print (”.”,time.sleep(0.3))
print ('.')
time.sleep(2)
os.system('cls
')
print (”TOTAL AMOUNT TO BE PAID = ”,amtl)
resno=random.randint(1000,25
46) x=no ofsleeper-totaf
print
if(x>0):
confirmation
()
dump(fout1)
break
else:
pending()
dump(tick,foutl
) break
except:
pass
if(f==0):
time.sleep(2)
print (”\n\n\n\n\n\n\t\t\t\t NO SUCH TRAINS
FOUND !!”) time.sleep(2)
print
prin
t
prin
t

train.nv

def init
():
trainno=
0
no
ofac1stclass=0 no
ofac2ndclass=0
no
ofac3rdclass=0
no ofsleeper=0
totalseats=0
trainname=”
startingpt=
destination=”
def getinput():
print
(”=”*80)
print (”\t\t\t ENTER THE TRAIN DETAILS”)
print
print(”=”*80)
trainname=input(”ENTER THE TRAIN NAME : ”).upper()
print
trainno=int(input(”ENTER THE TRAIN NUMBER: ”))
print
no ofaclstclass=int(input(”ENTER NO OF AC FIRST CLASS SEATS TO BE RESERVED : ”))
print
no ofac2ndclass=int(input(”ENTER NO OF AC SECOND CLASS SEATS TO BE RESERVED : ”))
print
no ofac3rdclass=int(input(”ENTER NO OF AC THIRD CLASS SEATS TO BE RESERVED : ”))
print
no ofsleeper=int(input(”ENTER NO OF SLEEPER CLASS +SEATS TO BE RESERVED : ”))
print
startingpt=input(”ENTER THE STARTING POINT : ”)
print
destination=input(”ENTER THE DESTINATION POINT : ”)
os.system('cls')
def output():
print
(”=”*80)
print
print (”THE ENTERED TRAIN NAME IS : ”,trainname)
print (”THE TRAIN NUMBER IS : ”,train no)
print (”STARTING POINT ENTERED IS : ”,startingpt)
print (”DESTINATION POINT ENTERED IS : ”,destination)
print (”NO OF AC FIRST CLASS SEATS RESERVED ARE :”,no ofac lstclass) print
(”NO OF AC SECOND CLASS SEATS RESERVED ARE :”,no ofac2ndclass) print
(”NO OF AC THIRD CLASS SEATS RESERVED ARE :”,no ofac3rdclass) print (”NO
OF SLEEPER CLASS SEATS RESERVED ARE :”,no ofsleeper)
print
print (”=”*80)
def
gettrainname():
return
(trainname) def
gettrainno():
return(trainno)
def getno ofac lstclass():
return(no ofaclstclass)
def getno ofac2ndclass():
return(no
ofac2ndclass)
def getno ofac3rdclass():
return(no
ofac3rdclass)
def getno ofsleeper():
return (no
ofsleeper)
def getstartingpt():
return
(startingpt) def
getdestination():
return (destination)

MAIN CODE USED


from pickle import
load,dump import time
import
random
import os
import tickets
import train

def menu():
tr=train()
tick=tickets(
) print
print ("WELCOME TO DIVESH AGENCY".center(80))
while True:
print
print ("=”*80)
print (" \t\t\t\t RAILWAY”)
print
print ("=”*80)
print
print ("\t\t\t1. **UPDATE TRAIN
DETAILS.") print
print ("\t\t\t2. TRAIN DETAILS.
") print
print ("\t\t\t3. RESERVATION OF TICKETS.")
print
print ("\t\t\t 4. CANCELLATION OF TICKETS. ")
print
print ("\t\t\t 5. DISPLAY PNR
STATUS.") print
print ("\t\t\t6. QUIT.")
print("** - office use
.............................................."
)
ch=int(input("\t\t\t ENTER YOUR CHOICE :
")) os.system('cls')
print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\
t\t\t\t\t\t\t LOADING. .",time.sleep(1))
print(".",time.sleep(0 5))
print
(".",time.sleep(2))
os.system('cls')
=’y'
while (x.lower()=='y'):
fout=open("trdetai1s.dat","ab
") tr.getinput()
dump(tr,fout)
fout.close()
print("\n\n\n\n\n\n\n\n\n\n\n\t\t\t UPDATING TRAIN LIST
PLEASE WAIT . .",time.sleep(1))
print (("."), time.sleep(0.5))
print
(("."),time.sleep(2))
os.system('cls')
print ("\n\n\n\n\n\n\n\n\n\n\n”)
x=input(”\t\t DO YOU WANT TO ADD ANY MORE TRAINS DETAILS ? ")
os.system('cls
') continue
e1if(j !=r): print("\
n\n\n\n\n”)
print("WRONG PASSWORD".center(80))
while True:
print("*"*80
)
print("\t\t\t\tTRAIN
DETAILS") print("*"*80)
print
tr=load(fin
)
tr.output(
)
input("PRESS ENTER TO VIEW NEXT TRAIN DETAILS”)
os.system('cls
') except:
pass
elif ch=
print('='*8
0)
print ("\t\t\t\
tRESERVATIONOFTICKETS”) print('='*80)
print
tick.reservation()
elif ch==
print("="*80)
print("\t\t\t\tCANCELLATION OF
TICKETS") print
print("="*80)
print
tick.cancellation(
)
elif ch
print ("=”*80)
print("PNR
STATUS".center(80))
print("="*80)
print
tick.display(
)

elif ch
quit()
input("PRESS ENTER TO GO TO BACK MENU”.center(80))
os.system('cls
') menu()
print("\t\t\t\t\n\n\n\n\n\t THANK YOU")
print("\n\t\t\t\DONE BY:-")
print("\t\t\t\t PRAKHAR
PACHPOR") print("\t\t\t\t XII-A”)
print("\t\t\t\t 22")

print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\
tLOADING..”,time.slee

print (”.”),
time.sleep(o.5)
print (".")
time.sleep(2)
os.system('cls')
menu(
)
REQUIREMENTS
Python 3.3 or higher
Python IDLE
Computer with 128 MB of RAM

BIBILIOGRAPHY
Sumita Arora’s Book for CS Class XI

Sumita Arora’s Book for CS Class XII

Github

StackExchange

MADE BY:

MANAV SUNDRANI
KHUSHBU YADAV
URMILA SONI

You might also like