Railway Reservation System Using Python
Data science projects in pondicherry
Create New

Railway Reservation System Using Python

Project period

09/05/2020 - 10/30/2020

Views

69

0

Project Category

Computer Science



Railway Reservation System Using Python
Railway Reservation System Using Python

Getting train tickets on spot in the railway station can have many negative aspects. When coming to the station during heavy traffic, we could not collect tickets on spot. Collecting on spot tickets will be good for something but on festive occasions, we may not get a ticket because many people overcrowd for getting the tickets. Sometimes we may also miss the train while standing in the queue for buying tickets. So, I created a project for booking train tickets online. This would be useful for the people who travel by train especially during exam times and during festival times.

Why: Problem statement

My elder sister prepared very well for the government examination. She needed to go to Chennai to write the exam. But she didn’t book a railway ticket, she went to the railway station, she waited long hours in the queue to get a train ticket.  And also she missed her train. She felt very bad for missing the first train and having tension. That’s the reason, I thought to start a project train ticket booking system using python programming. Hereafter, my sister won’t miss the train because she can book the train ticket and attend the exam without tension. 

How: Solution description

In order to overcome this problem, I created a project called “Train ticket booking system”. There are five systems I bought in this project.

  • Create a New Account

  • Check PNR

  • Check seat availability

  • Book Ticket

  • Cancel Ticket

1. Create a New Account

Create a new account by entering the username and password. After registration, log in to the account by giving a registered username and password. It gives us id. Following the above-mentioned instructions will result in the successful creation of your new account.

2. Check PNR:

The PNR live status of your train ticket can be checked in no time! For the Indian Railway PNR status check, all you need to do is enter your PNR number and click the button indicated. A new window will appear showing your current PNR status live. There is a popular confusion among users if you can check PNR status online by entering the passenger's name or not. However, since the personal details of each passenger are kept confidential. The PNR number consists of 10 digits, where the first 3 digits specify the PRS from which the ticket is booked. The first digit of the PNR number specifies the zone of the train of the ticket.

3. Check seat availability

We can check the availability of seats in the real world. This can be done by entering the From and to station Name/Code along with travel dates and travel class to know the current train seat availability.

4. Book Ticket

We can book tickets. It asks for the arrival and departure location. The system checks for availability and provides the number of seats the customer asks for. 

The system's purpose is to allow a management system for the railway station. The system allows easy access to the railway routes and trains available as well as the current fares for the railway station staff to manage their internal workings. 

This contains details of all the types of trains at the station. It also tells of available trains at the station as well as their status- which route are they on and whether they are available or not.

5. Cancel Ticket

To cancel the train ticket, you just need two things: PNR number and train number. We can cancel the tickets whenever we want.

How is it different from competition

This project is really used for all the passengers, who are traveling by train. But I mainly proposed this for students who are going for the exams. They can go to the exams without delay. This project provides some facilities for passengers that are to enquire about the trains available on the basis of source and destination, Booking and Cancellation of tickets, enquire about the status of the booked ticket, etc.,

Who are your customers

When I compared the existing project most of the people were done with the train booking system using HTML, CSS, PHP, etc and also it is difficult to use. But my project is really unique compared to others. Because I did this project using Simple python. This system has some advantages that are mentioned below:
Convenient - You can book or cancel your tickets sitting in the comfort of your home or office.
Saves Time and Effort - You can save the time needed to travel to the railway reservation office and wait in the queue for your turn.

Project Phases and Schedule

Phase 1: Study various booking management systems

Phase 2: Learn syntax and write code for each session

Phase 3: Testing and Debugging

Resources Required

Anaconda tool: Anaconda is a free and open-source distribution of the python and R programming languages for scientific computing (Data science, Machine learning applications, Large-scale data processing, predictive analysis, etc .) that aims to simplify package management and deployment.
Languages used: Python 3.7
Python 3.7 is officially released. This new Python version has been in development since September 2016, And now we all get to enjoy the results of the core developer’s hard work.
Jupyter notebook: A jupyter notebook is similar to the Ipython console, but, instead of only being able to work with a single line of code at a time, you Can easily edit and re-execute any code that has been written in a notebook. Furthermore, you can save a notebook, and thus return to it later. Additionally, a notebook provides many terrific features. For instance, you can embed visualizations of data within a notebook, and write blocks of nicely-formatted text (using the Markdown syntax), for presenting and Explaining the contents of the notebook.

Download:
Project Code Code copy
/* Your file Name : RAILWAY .ipynb */
/* Your coding Language : python */
/* Your code snippet start here */
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------------------------------------Welcome to Railway Reservation Portal----------------------------------------------\n",
      "-------------------------------------------------------------------------------------------------------------------------------------\n",
      "Choose one of the following option:-\n",
      "1.Book Ticket\n",
      "2.Cancel Ticket\n",
      "3.Check PNR \n",
      "4.Check seat availibity\n",
      "5.Create new account\n",
      "6.Check previous transaction\n",
      "Option = 5\n",
      "Enter your user name:- Jerina\n",
      "Enter your password :- 15111999\n",
      "Enter your hometown :- kallacuruchi\n",
      "Enter your phone number :- 9944325680\n",
      "Your user ID is :-  1802\n",
      "Choose one of the following option:-\n",
      "1.Book Ticket\n",
      "2.Cancel Ticket\n",
      "3.Check PNR \n",
      "4.Check seat availibity\n",
      "5.Create new account\n",
      "6.Check previous transaction\n",
      "Option = 1\n",
      "Enter your User ID = 1802\n",
      "Enter your password :- 15111999\n",
      "Welcome  Jerina  !\n",
      "Enter the source station:- hwr\n",
      "Enter the destination station:- kol\n",
      "Train Name :-  howrah   Number  12565   Day of Travel :-  Mon\n",
      "Enter the train number :- 12565\n",
      "No. of seats available in 1AC :- 33\n",
      "No. of seats available in 2AC :- 4\n",
      "No. of seats available in SL :- 12\n",
      "Enter the coach :- SL\n",
      "Enter the number of tickets :- 1\n",
      "Confirm Ticket(s) (y/n) ? :- y\n",
      "Booking Successful!\n",
      "\n",
      "\n",
      "Please note PNR number :-  125651802887 \n",
      "\n",
      "\n",
      "Choose one of the following option:-\n",
      "1.Book Ticket\n",
      "2.Cancel Ticket\n",
      "3.Check PNR \n",
      "4.Check seat availibity\n",
      "5.Create new account\n",
      "6.Check previous transaction\n",
      "Option = 2\n",
      "Enter the PNR number :- 125651802887\n",
      "User name:-  Jerina\n",
      "Train name:-  howrah\n",
      "No. of Tickets Booked :-  1\n",
      "Do you want to cancel(y/n):- y\n",
      "Enter your id :- 1802\n",
      "Enter the password :- 15111999\n",
      "\n",
      "\n",
      "Ticket Cancelled.\n",
      "\n",
      "\n",
      "Choose one of the following option:-\n",
      "1.Book Ticket\n",
      "2.Cancel Ticket\n",
      "3.Check PNR \n",
      "4.Check seat availibity\n",
      "5.Create new account\n",
      "6.Check previous transaction\n",
      "Option = 4\n",
      "Enter the source station:- hwr\n",
      "Enter the destination station:- kol\n",
      "Train Name :-  howrah   Number  12565   Day of Travel :-  Mon\n",
      "Enter the train number :- 12565\n",
      "No. of seats available in 1AC :- 33\n",
      "No. of seats available in 2AC :- 4\n",
      "No. of seats available in SL :- 11\n",
      "Choose one of the following option:-\n",
      "1.Book Ticket\n",
      "2.Cancel Ticket\n",
      "3.Check PNR \n",
      "4.Check seat availibity\n",
      "5.Create new account\n",
      "6.Check previous transaction\n",
      "Option = 3\n",
      "Enter the PNR number :- 125651802887\n",
      "User name:-  Jerina\n",
      "Train name:-  howrah\n",
      "No. of Tickets Booked :-  1\n"
     ]
    }
   ],
   "source": [
    "import pickle\n",
    "import sys\n",
    "import random\n",
    "\n",
    "\n",
    "class train:\n",
    "    def __init__(self,name = '', num = 0, arr_time = '',dep_time = '',src = '' ,des = '',day_of_travel = '',seat_available_in_1AC = 0,seat_available_in_2AC = 0,seat_available_in_SL = 0,fare_1ac = 0, fare_2ac = 0 ,fare_sl = 0):\n",
    "        self.name = name\n",
    "        self.num = num\n",
    "        self.arr_time = arr_time\n",
    "        self.dep_time = dep_time\n",
    "        self.src = src\n",
    "        self.des = des\n",
    "        self.day_of_travel = day_of_travel\n",
    "        self.seats = {'1AC' : seat_available_in_1AC, '2AC': seat_available_in_2AC,'SL': seat_available_in_SL}\n",
    "        self.fare = {'1AC' : fare_1ac,'2AC' : fare_2ac ,'SL' : fare_sl}\n",
    "    def print_seat_availablity(self):\n",
    "    \tprint(\"No. of seats available in 1AC :- \"+str(self.seats['1AC']))\n",
    "    \tprint(\"No. of seats available in 2AC :- \"+str(self.seats['2AC']))\n",
    "    \tprint(\"No. of seats available in SL :- \"+str(self.seats['SL']))\n",
    "    def check_availabilty(self,coach='',ticket_num = 0):\n",
    "    \tcoach = coach.upper()\n",
    "    \tif coach not in ('SL','1AC','2AC'):\n",
    "    \t\tprint_seat_availablity()\n",
    "    \t\tcoach = input(\"Enter the coach(1AC/2AC/SL) :-\")\n",
    "    \telse:\n",
    "    \t\tif self.seats[coach] == 0:\n",
    "    \t\t\treturn False\n",
    "    \t\telif self.seats[coach] >= ticket_num:\n",
    "    \t\t\treturn True\n",
    "    \t\telse:\n",
    "    \t\t\treturn False\n",
    "    def book_ticket(self,coach = '',no_of_tickets = 0):\n",
    "    \tself.seats[coach] -= no_of_tickets\n",
    "    \treturn True\n",
    "\n",
    "\n",
    "class user:\n",
    "\tdef __init__(self,uid = 0,name = '',hometown = '',cell_num = '',pwd = ''):\n",
    "\t\tself.uid = uid\n",
    "\t\tself.name = name\n",
    "\t\tself.hometown = ''\n",
    "\t\tself.cell_num = ''\n",
    "\t\tself.pwd = pwd\n",
    "\t\tself.history = {}\n",
    " # def book_ticket(self)\n",
    "\n",
    "\n",
    "\n",
    "class ticket:\n",
    "\tdef __init__(self,train,user,ticket_num):\n",
    "\t\tself.pnr = str(train.num)+str(user.uid)+str(random.randint(100,999))\n",
    "\t\tself.train_name = train.name\n",
    "\t\tself.user_name = user.name\n",
    "\t\tself.ticket_num = ticket_num\n",
    "\t\tuser.history.update({self.pnr : self})\n",
    "\t\tticket_dict.update({self.pnr : self})\n",
    "\n",
    "\n",
    "\n",
    "def book_ticket():\n",
    "\ttry:\n",
    "\t\tuid = int(input(\"Enter your User ID = \"))\n",
    "\texcept ValueError:\n",
    "\t\tprint(\"\\nEnter valid User ID\\n\")\n",
    "\t\tbook_ticket()\n",
    "\tpwd = input(\"Enter your password :- \")\n",
    "\tif uid in users and users[uid].pwd == pwd:\t\t\n",
    "\t\tprint(\"Welcome \",users[uid].name,\" !\")\n",
    "\telse:\n",
    "\t\tprint(\"\\n\\nNo such user ID / Wrong Password !\\n\\n\")\n",
    "\t\tmenu()\n",
    "\tcheck_seat_availabilty('p')\n",
    "\ttry:\n",
    "\t\tchoice = int(input(\"Enter the train number :- \"))\n",
    "\texcept ValueError:\n",
    "\t\tprint(\"\\n\\nPlease properly enter the train number.\\n\\n\")\n",
    "\t\tmenu()\n",
    "\t\tbook_ticket()\n",
    "\tif choice in trains:\n",
    "\t\t\ttrains[choice].print_seat_availablity()\n",
    "\telse:\n",
    "\t\tprint(\"\\n\\nEnter valid train number\\n\\n\")\n",
    "\t\tmenu()\n",
    "\tcoach = input(\"Enter the coach :- \")\n",
    "\tcoach = coach.upper()\n",
    "\tif coach in ('SL','1AC','2AC'):\t\n",
    "\t\tticket_num = int(input(\"Enter the number of tickets :- \"))\n",
    "\t\tif trains[choice].check_availabilty(coach,ticket_num):\n",
    "\t\t\tprompt = input(\"Confirm Ticket(s) (y/n) ? :- \")\n",
    "\t\t\tif prompt == 'y':\n",
    "\t\t\t\ttrains[choice].book_ticket(coach,ticket_num)\n",
    "\t\t\t\tprint(\"Booking Successful!\\n\\n\")\n",
    "\t\t\t\ttick = ticket(trains[choice],users[uid],ticket_num)\n",
    "\t\t\t\tprint(\"Please note PNR number :- \",tick.pnr,\"\\n\\n\")\n",
    "\t\t\t\tmenu()\n",
    "\t\t\telse:\n",
    "\t\t\t\tprint(\"Exiting...\\n\\n\")\n",
    "\t\t\t\tmenu()\n",
    "\t\telse:\n",
    "\t\t\tprint(ticket_num,\" tickets not available\")\n",
    "\t\t\tmenu()\n",
    "\telse:\n",
    "\t\tprint(\"\\n\\nEnter proper coach\\n\\n\")\n",
    "\t\tmenu()\n",
    "\n",
    "def cancel_ticket():\n",
    "\tpnr = input(\"Enter the PNR number :- \")\n",
    "\tif pnr in ticket_dict:\n",
    "\t\tcheck_pnr(pnr)\n",
    "\t\tchoice = input(\"Do you want to cancel(y/n):- \")\n",
    "\t\tif choice == 'y':\n",
    "\t\t\tuid = int(input(\"Enter your id :- \"))\n",
    "\t\t\tpwd = input(\"Enter the password :- \")\n",
    "\t\t\tif uid in users:\n",
    "\t\t\t\tif users[uid].pwd == pwd:\n",
    "\t\t\t\t\tprint(\"\\n\\nTicket Cancelled.\\n\\n\")\n",
    "\t\t\t\telse:\n",
    "\t\t\t\t\tprint(\"\\nEnter the right password\\n\")\n",
    "\t\t\telse:\n",
    "\t\t\t\tprint(\"\\nNo such user.Ticket not cancelled\\n\")\n",
    "\t\t\t\tmenu()\n",
    "\t\telse:\n",
    "\t\t\tprint(\"\\nTicket not cancelled\\n\")\n",
    "\t\t\tmenu()\n",
    "\tmenu()\n",
    "\n",
    "\n",
    "\n",
    "def check_seat_availabilty(flag = ''):\n",
    "\tsrc = input(\"Enter the source station:- \")\n",
    "\tdes = input(\"Enter the destination station:- \")\n",
    "\tflag_2 = 0\n",
    "\tfor i in trains:\n",
    "\t\tif trains[i].src == src and trains[i].des == des:\n",
    "\t\t\tprint(\"Train Name :- \",trains[i].name ,\" \" ,\"Number \",trains[i].num ,\" \",\"Day of Travel :- \",trains[i].day_of_travel)\n",
    "\t\t\tflag_2 += 1\n",
    "\tif flag_2 == 0:\n",
    "\t\tprint(\"\\n\\nNo trains found between the stations you entered.\\n\\n\")\n",
    "\t\tmenu()\n",
    "\tif flag == '':\n",
    "\t\tchoice = int(input(\"Enter the train number :- \"))\n",
    "\t\ttrains[choice].print_seat_availablity()\n",
    "\t\tmenu()\n",
    "\telse:\n",
    "\t\tpass\n",
    "\n",
    "def check_pnr(pnr_num = ''):\n",
    "\tif pnr_num == '':\n",
    "\t\tpnr_num = input(\"Enter the PNR number :- \")\n",
    "\tif pnr_num in ticket_dict:\n",
    "\t\tprint(\"User name:- \",ticket_dict[pnr_num].user_name)\n",
    "\t\tprint(\"Train name:- \",ticket_dict[pnr_num].train_name)\n",
    "\t\tprint(\"No. of Tickets Booked :- \",ticket_dict[pnr_num].ticket_num)\n",
    "\telse:\n",
    "\t\tprint(\"\\nNo such PNR number exists.\\n\")\n",
    "\t# menu()\n",
    "\n",
    "def create_new_acc():\n",
    "\tuser_name = input(\"Enter your user name:- \")\n",
    "\tpwd = input(\"Enter your password :- \")\n",
    "\tuid = random.randint(1000,9999)\n",
    "\thometown = input(\"Enter your hometown :- \")\n",
    "\tcell_num = input(\"Enter your phone number :- \")\n",
    "\tu = user(uid, user_name, hometown, cell_num, pwd)\n",
    "\tprint(\"Your user ID is :- \",uid)\n",
    "\tusers.update({u.uid : u})\n",
    "\tmenu()\n",
    "\n",
    "\n",
    "\n",
    "t1 = train('odisha',12345,'12:34','22:12','ctc','kgp','Wed',30,23,43,2205,320,234)\n",
    "t2 = train('howrah',12565,'02:34','23:12','hwr','kol','Mon',33,4,12,3434,435,234)\n",
    "t3 = train('bangalore',22353,'11:56','03:12','ctc','ban','Fri',33,24,77,455,325,533)\n",
    "trains = {t1.num:t1,t2.num:t2,t3.num:t3}\n",
    "# trains.update({int(input(\"Enter the train number=\")) : train(input(\"Enter the train name=\"),34353,'12:34','11:52','Wed',11,35,76)})\n",
    "# print(train_dict[12565].name)\n",
    "u1 = user(1212,'dibya das','cuttack','7478021777','dibyadas')\n",
    "users={u1.uid : u1}\n",
    "ticket_dict = {}\n",
    "\n",
    "# train_file = open(\"t.pkl\",'wb')\n",
    "# user_file = open(\"u.pkl\",'wb')\n",
    "# pickle.dump(trains,train_file)\n",
    "# pickle.dump(users,user_file)\n",
    "# train_file.close()\n",
    "# user_file.close()\n",
    "# train_file = open(\"t.pkl\",\"rb\")\n",
    "# user_file = open(\"u.pkl\",\"rb\")\n",
    "# trains = pickle.load(train_file)\n",
    "# users = pickle.load(user_file)\n",
    "# train_file.close()\n",
    "# user_file.close()\n",
    "\n",
    "print(\"--------------------------------------------------Welcome to Railway Reservation Portal----------------------------------------------\")\n",
    "print(\"-------------------------------------------------------------------------------------------------------------------------------------\")\n",
    "\n",
    "\n",
    "def menu():\n",
    "\tprint(\"Choose one of the following option:-\")\n",
    "\tprint(\"1.Book Ticket\")\n",
    "\tprint(\"2.Cancel Ticket\")\n",
    "\tprint(\"3.Check PNR \")\n",
    "\tprint(\"4.Check seat availibity\")\n",
    "\tprint(\"5.Create new account\")\n",
    "\tprint(\"6.Check previous transaction\")\n",
    "\ttry:\n",
    "\t\toption = int(input(\"Option = \"))\n",
    "\texcept ValueError:\n",
    "\t\tprint(\"\\n\\nPlease enter a valid option.\\n\\n\")\n",
    "\t\tmenu()\n",
    "\tif option == 1:\n",
    "\t\tbook_ticket()\n",
    "\telif option == 2:\n",
    "\t\tcancel_ticket()\n",
    "\telif option == 3:\n",
    "\t\tcheck_pnr()\n",
    "\telif option == 4:\n",
    "\t\tcheck_seat_availabilty()\n",
    "\telif option == 5:\n",
    "\t\tcreate_new_acc()\n",
    "\n",
    "\n",
    "menu()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
View on Github
Reservation

Comments

Leave a Comment

Post a Comment

Are you Interested in this project?


Do you need help with a similar project? We can guide you. Please Click the Contact Us button.


Contact Us

Social Sharing