0% found this document useful (0 votes)
52 views

21BCM055 - TrainTicketReservation - CLI Python

This program allows users to reserve train seats on different routes through a command line interface. It takes user input for passenger details like name, phone number and gender. It displays available trains on the selected route and takes input for train, coach and seat numbers. It then calculates the ticket amount and allows the user to pay through credit/debit card. Upon successful payment, it generates and displays the ticket with passenger and journey details. The program runs interactively, allowing multiple users to reserve seats for different trains.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

21BCM055 - TrainTicketReservation - CLI Python

This program allows users to reserve train seats on different routes through a command line interface. It takes user input for passenger details like name, phone number and gender. It displays available trains on the selected route and takes input for train, coach and seat numbers. It then calculates the ticket amount and allows the user to pay through credit/debit card. Upon successful payment, it generates and displays the ticket with passenger and journey details. The program runs interactively, allowing multiple users to reserve seats for different trains.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

PROGRAM 8 (TRAIN SEATS RESERVATION SYSTEM (CLI))

from inputimeout import inputimeout

class train_reserve:

def get_info():

inf['name']=input("Enter Name : ")

inf['phone no']=input("Enter Phone no : ")

inf['gender']=input("Gender (M/F) : ")

venues=['coimbatore','chennai','bangalore','calcutta']

inf['starting_point']=input("enter starting location {} : ".format(venues))

venues.remove(inf['starting_point'])

inf['destination']=input("destination {} :".format(venues))

def train_booking():

trains={'coimbatore-chennai':[['Vande Bharat Express','8:30 AM'],[{'1 A':[1965,50]},{'2


A':[1170,100]},{'3 A':[835,130]},{'SL':[325,150]}]],'chennai-bangalore-calcutta / chennai-calcutta':[['Duronto
Express','9:30 AM'],[{'1 A':[3665,50]},{'2 A':[2170,50]},{'3 A':[1895,80]},{'SL':[1325,100]}]],'coimbatore-
chennai-bangalore-calcutta / coimbatore-bangalore / coimbatore-calcutta /chennai-calcutta':[['Express
train','11:00 AM'],[{'1 A':[4665,30]},{'2 A':[4170,120]},{'3 A':[3895,140]},{'SL':[925,180]}]],'chennai-
bangalore':[['Indian Express','11:45 AM'],[{'1 A':[365,80]},{'2 A':[270,130]},{'3 A':[195,140]},{'SL':[95,200]}]]}

path=[]

journey=inf['starting_point']+'-'+inf['destination']

print("Available trains")

for t in trains:

if str.__contains__(t,journey):

print("Train name : ",trains[t][0][0],end="\n")

path.append(trains[t])

path.append(trains[t][0][0])

print("Train Timing : {}".format(trains[t][0][1]))


inf['train']=input("Enter a train that you want to make travel : ")

inf['coach']=input("enter coach {} :".format('1 A / 2 A / 3 A / SL'))

accessing_dict=path[path.index(inf['train'])-1][1][0 if inf['coach']=="1 A" else 1 if


inf['coach']=="2 A" else 2 if inf['coach']=="3 A" else 3][inf['coach']]

inf['price']=accessing_dict[0]

print("Respective Price per seat : ",inf['price'])

total_seats=accessing_dict[1]

seat=input("enter the seats from 1 to {} : ".format(total_seats)).split(",")

seat.sort()

verify=str(inf['train'])+"-"+str(inf['coach'])

if str.__contains__(str(reserved),verify):

if str.__contains__(str(seating),str(seat)):

print("already reserved")

print("__________________",end="\n")

obj.train_booking()

else:

inf['seats']=seat

else:

inf['seats']=seat

inf['amount']=len(inf['seats'])*inf['price']

def download_ticket():

print("\n----------------------- INDIAN RAILWAYS-----------------")

print("\n ******passenger details******")

print("\n Name : {}".format(inf['name']))

print("\n Phone no : {}".format(inf['phone no']))

print("\n Beginning of venture : {}".format(inf['starting_point']))

print("\n destination : {}".format(inf['destination']))

print("\n_____________________________________________")
print("\n****** Journey details ******")

print("\n Train Name : {}".format(inf['train']))

print("\n Coach : {}".format(inf['coach']))

print("\n Seats Booked : {}".format(inf['seats']))

print("\n Total Amount : {}".format(inf['amount']))

print("\n_____________________________________________")

joint=str(inf['train'])+"-"+str(inf['coach'])

seating.append(inf['seats'])

reserved.append(joint)

def payment():

print("Amount : {}".format(inf['amount']))

bank=['Credit Card','Debit Card']

payment_medium=input("Choose payment method {}:".format(bank))

if payment_medium=="Credit Card" or payment_medium=="Debit Card":

try:

cred_no=input("Card Number : ")

cvv=input("CVV no : ")

time_over = inputimeout(timeout=40)

submit=input("PAY / CANCEL : ")

if submit=="CANCEL":

print("reservation process terminated...")

elif submit=="PAY":

obj.download_ticket()

else:

print("Not Valid.")

obj.payment()
except Exception:

time_over="Your Session got expired"

print(time_over)

obj.payment()

reserved=[]

inf={}

seating=[]

while(True):

obj=train_reserve

obj.get_info()

obj.train_booking()

obj.payment()

switch=input("\n\n stay/leave:")

if switch=="leave":

break

print("reservation process terminated...")

OUTPUT:

Enter Name : Parthiban A

Enter Phone no : +91 9874560981

Gender (M/F) : M

enter starting location ['coimbatore', 'chennai', 'bangalore', 'calcutta'] : chennai

destination ['coimbatore', 'bangalore', 'calcutta'] :bangalore

Available trains

Train name : Duronto Express

Train Timing : 9:30 AM

Train name : Express train

Train Timing : 11:00 AM


Train name : Indian Express

Train Timing : 11:45 AM

Enter a train that you want to make travel : Duronto Express

enter coach 1 A / 2 A / 3 A / SL :2 A

Respective Price per seat : 2170

enter the seats from 1 to 50 : 1,3,2,5,4

Amount : 10850

Choose payment method ['Credit Card', 'Debit Card']:Credit Card

Card Number : 267829212345

CVV no : 121

PAY / CANCEL : PAY

----------------------- INDIAN RAILWAYS-----------------

******passenger details******

Name : Parthiban A

Phone no : +91 9874560981

Beginning of venture : chennai

destination : bangalore

_____________________________________________

****** Journey details ******

Train Name : Duronto Express


Coach :2A

Seats Booked : ['1', '2', '3', '4', '5']

Total Amount : 10850

_____________________________________________

stay/leave:stay

Enter Name : LeoDas A

Enter Phone no : +91 9874560981

Gender (M/F) : M

enter starting location ['coimbatore', 'chennai', 'bangalore', 'calcutta'] : chennai

destination ['coimbatore', 'bangalore', 'calcutta'] :bangalore

Available trains

Train name : Duronto Express

Train Timing : 9:30 AM

Train name : Express train

Train Timing : 11:00 AM

Train name : Indian Express

Train Timing : 11:45 AM

Enter a train that you want to make travel : Duronto Express

enter coach 1 A / 2 A / 3 A / SL :2 A

Respective Price per seat : 2170

enter the seats from 1 to 50 : 1,3,2,4,5

already reserved

__________________

Available trains
Train name : Duronto Express

Train Timing : 9:30 AM

Train name : Express train

Train Timing : 11:00 AM

Train name : Indian Express

Train Timing : 11:45 AM

Enter a train that you want to make travel : Duronto Express

enter coach 1 A / 2 A / 3 A / SL :2 A

Respective Price per seat : 2170

enter the seats from 1 to 50 : 6,7,8,9,10

Amount : 10850

Choose payment method ['Credit Card', 'Debit Card']:Credit Card

Card Number : 267829212345

CVV no : 121

PAY / CANCEL : PAY

----------------------- INDIAN RAILWAYS-----------------

******passenger details******

Name : LeoDas A

Phone no : +91 9874560981

Beginning of venture : chennai

destination : bangalore

_____________________________________________
****** Journey details ******

Train Name : Duronto Express

Coach :2A

Seats Booked : ['10', '6', '7', '8', '9']

Total Amount : 10850

_____________________________________________

stay/leave:leave

reservation process terminated...

[Program finished]

You might also like