Computer Science Project - 25 - Railways
Computer Science Project - 25 - Railways
SESSION :2021-22
Primarily I would like to thank God for being able to complete the project with success. Then I would like to thank my CS teacher Ms
Pooja, whose valuable guidance has been ones that helped me patch this project and make it full proof success. Her supervisions
and instructions have served me a major contribution towards completion of project.
Then I would like to thank my parents, friends who helped me with their valuable suggestions and guidance has been helpful in
various phases of completion of project. Last but not the least I would like to thank my classmates who have helped me a lot.
INDEX
1. ABSTRACT
2. INTRODUCTION
3. MODULE DESCRIPTION
4. CODING
5. OUTPUT
6. LIMITATATIONS
7. BIBLIOGRAPHY
ABSTRACT
This project is about Indian railway reservation system. The tickets are usually booked through
online official site of railways. This project explains how reservation is being done in Indian railways.
The procedure is explained step by step. Proper comments have been given at desired location to
make the project user friendly. Various function and structures are used to make a complete use of
this language. This project is well versed with 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.
ABOUT INDIAN RAILWAY
Indian Railways is the state-owned railway company of India; it has a complete monopoly ove1
country's rail transport. Indian Railways (IR) has one of the largest and busiest rail networks in
world, transporting over 5 billion passengers and over 350 million tonnes of freight annually. 11
also the world's largest commercial or utility employer, having more than 1.6 million regular
employees on its payroll.
Railways were frrst introduced to India in 1853, and by 1947, the year of India's independence,
had grown to forty-two rail systems. In 1951 the systems were nationalized as one unit, to beco
one of the largest networks in the world.
Indian Railways operates both long distances, as well as suburban rail systems. It operates 8, 70
passenger trains and transports around five billion annually across twenty-seven states and thre
union territories (Delhi, Pondicherry and Chandigarh). Sikkim is the only state not connected. ~
Railway Budget deals with the induction and improvement of existing trains and routes, the
modernization 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.
CODING
MODULES USED
tickets.py
def _init_():
no_ofacl stclass=0
totaf=0
no_ofac2ndclass=0
no_ofac3rdclass=0
no_ofsleeper=0
no_oftickets=0
name="
age="
resno=0
status="
def ret():
return(resno)
def retname():
return(name)
def display():
f=0
fin I =open{"tickets.dat","rb")
if not fin!:
print ("ERROR")
I
else:
print
.
n =int(input("ENTER PNR NUMBER : "))
print ("\n\n")
print ("FETCHING DATA . . .".center(S0))
time.sleep( I)
print
print('PLEASE W AIT... !!'.center{80}}
time.sleep(l)
os.system('cls')
try:
while True:
tick=load(finl)
if( n ==tick.ret() ):
f=l
print ("="•SO)
print("PNR STATUS".center(S0))
print ("="•SO)
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
fin I.close()
if(f==0):
print
print ("WRONG PNR NUMBER..!!")
print
def pending(): I
status="WAITING LIST"
print ("PNR NUMBER :",resno)
print I
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,fout)
elif(z==r):
f=l
except:
pass
fin.close()
fout.close()
os.remove("tickets.dat")
os.rename("tem p.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=l
print
print ("-"•so)
no_ofac lst=tr.getno_ofac lstclass()
no_ofac2nd=tr.getno_ofac2ndclass()
no_ofac3rd=tr.getno_ofac3rdclass()
no_ofsleeper=tr.getno_ofsleeper()
if(f==l):
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 ("I.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('ds')
amtl=0
if(c==l):
no_oftickets=int(input("ENTER NO_OF FIRST CLASS AC SSEATS TO BE BOOKED:"))
i=l
!
while(i<=no_oftickets):
totaf=totaf+ I
amtl=IOOO•no_oftickets
i=i+l
print
print("PROCESSING..",time.sleep(0.5))
print (".",time.sleep(0.3))
print('.')
time.sleep(2)
os.system('ds')
print ("TOTAL AMOUNT TO BE PAID = ",amtl)
resno=int(random.randint(l000,2546))
x=no_ofaclst-totaf
print
if(x>0):
confirmation()
dump(foutl)
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=l
while(i<=no_oftickets):
totaf=totaf+ 1
amtl=900•no_oftickets
i=i+l
print
print ("PROCESSING. .",time.sleep(0.S))
print (".",time.sleep(0.3))
print ('.',time.sleep(2))
os.system('cls')
print ("TOTAL AMOUNT TO BE PAID = ",amtl)
resno=random.randint(l000,2546)
x=no_ofac2nd-totaf
print
if(x>0):
confirmation()
dump(foutl)
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=l
while(i<=no_oftickets):
totaf=totaf+ 1
amtl=S00•no_oftickets
i=i+l
print
print ("PROCESSING. .",time.sleep(0.S))
print (".",time.sleep(0.3))
print ('.')
time.sleep(2)
os.system('cls')
print ("TOTAL AMOUNT TO BE PAID = ",amtl)
resno=random.randint(l000,2546)
x=no_ofac3rd-totaf
print
if(x>0):
confirmation()
dump(foutl)
break
else:
pending()
dump(tick,foutl)
break
elif(c==4):
no_oftickets=int(input("ENTER NO_OF SLEEPER CLASS SEATS TO BE BOOKED:"))
i=l
while(i<=no_oftickets):
totaf=totaf+ I
amtl=SS0•no_oftickets
i=i+I
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,2546)
x=no_ofsleeper-totaf
print
if(x>0):
confirmation()
dump(foutl)
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
print
print
train,py
def _init_():
trainno=0
no_ofacl stclass=0
no_ofac2ndclass=0
no_ofac3rdclass=0
no_ofsleeper=0
totalseats=0
train name="
startingpt=""
destination="
def getinput():
print ("="•80)
print ("\t\t\t ENTER THE TRAIN DETAILS")
print
print("="•so)
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 ("="•so)
print
print ("THE ENTERED TRAIN NAME IS : ",trainname)
print ("THE TRAIN NUMBER IS: ",trainno)
print ("STARTING POINT ENTERED IS: ",startingpt)
print ("DESTINATION POINT ENTERED IS: ",destination)
print ("NO_OF AC FIRST CLASS SEATS RESERVED ARE :",no_ofaclstclass)
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 ("="•so)
def gettrainname():
return (trainname)
def gettrainno():
return(trainno)
def getno_ofaclstclass():
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)
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\tl . * *UPDATE TRAIN DETAILS.")
print
print ("\t\t\t2. TRAIN DETAILS. ")
print
print ("\t\t\t3. RESERVATION OF TICKETS.")
print
print ("\t\t\t4. CANCELLATION OF TICKETS. ")
print
print ("\t\t\tS. DISPLAY PNR STATUS.")
print
print ("\t\t\t6. QUIT.")
Pn·nt(" * * - o ffi ce use......")
ch=int(input("\t\t\t ENTER YOUR CHOICE:"))
os.system ('els')
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(o.s))
print (" .",time.sleep(2))
os.system('cls')
EID
H-H I H IH I rnn I H DI rn I LS
if ch== l:
j="password"
r=input("\n\n\n\n\n\n\n\n\n\n\n\t\t\t\tENTER THE PASSWORD:")
os.system ('els')
if (j==r):
x='y'
while (x.lower0=='y'):
fout=open("trdetails.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(o.s))
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
elif(j !=r):
print("\n \n \n \n \n")
print("WRONG PASSWORD".center(8o))
RAILUAY mr
---------- -- -- --- ------=---=---=-===-===--
,' C:\Python27\python.exe
HA I L~!AY
H l !:IHIJ
HI.IOI
OI !I O H O F I I C l<l· IS
l'NH NIIMIII H : I ! I?
! : I fl I 11 :: COHFIHMED
elif ch==3:
print('='*80)
print ("\t\t\t\tRESERVATION OF TICKETS")
print('='*80)
print
tick.reservation()
rl C:\Python27\pytho ( □J a
RA I L\!AY
- - ----- --- ------------ -- ---------------- - --- ----
4. CAHCELLATI OH OF TICkETS.
5 . DI SPLAY PHR STATUS.
6. QUIT .
'' I t i I ,. 11 I ••• • •••
,' C:\Python27\python.exe
CAHCELLATIOH OF TICkETS
CANCELLATION OF TICKETS
=~==~====~===============================~= --
TI Ct<U CANCFLLFD
PRESS ENTER TO GO TO BACK MENU
elif ch;::=4:
print("="*80)
print("\t\t\t\tCANCELLATION OF TICKETS")
print
print("="*8o)
print
tick.cancellation()
elif ch==S:
print ("="*80)
print("PNR STATUS".center(So))
print("="*80)
print
tick.display()
D C:\ WINOOWS\.py.ei.e
elif ch==6:
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")