0% found this document useful (0 votes)
50 views26 pages

CS Railway Managemnet Project Class 12

The document describes an online train ticket booking system with functions for signing up, logging in, booking tickets, checking tickets, cancelling tickets and logging out. It includes functions for getting seat availability and price details on different trains running between cities.
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)
50 views26 pages

CS Railway Managemnet Project Class 12

The document describes an online train ticket booking system with functions for signing up, logging in, booking tickets, checking tickets, cancelling tickets and logging out. It includes functions for getting seat availability and price details on different trains running between cities.
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/ 26

import random

import mysql. connector as mys

mycon=mys.connect(host="localhost",user="root”,
password="dev2006")

mycursor=mycon.cursor()

mycon.commit()

from tabulate import tabulate

def MENU():

ch=1

while True:

print("------------WELCOME TO IRCTC-----------")

print('1.SIGN IN')

print('2.SIGN UP')

print("3.DELETE ACCOUNT")

print('3.EXIT')
ch1=int(input("enter ur choice:"))

if ch1 == 1:

a=checking()

if a==True:

print('Welcome!')

main()

else:

continue

elif ch1 == 2:

a=checking_1()

if a==True:

main()

else:

print('Password already exists')

elif ch1 == 3:
c3=checking_2()

if c==True:

print("ACCOUNT DELETED")

continue

else:

print("your password or user_name is incorrect")

continue

elif ch1==4:

print("THANK YOU")

break

else:

print("error")

break

print("1.yes")

print("2.no")

ch=int(input("do u want to continue"))


def main():

print("1.yes")

print("2.no")

c=int(input("do u want to continue"))

while c == 1:

print('1.TICKET BOOKING')

print('2.TICKET CHECKING')

print('3.TICKET CANCELLING')

print('4.LOG OUT')

ch = int(input('ENTER YOUR CHOICE'))

if ch == 1:

ticket_book()

elif ch == 2:

ticket_check()

elif ch == 3:

ticket_cancel()

elif ch == 4:
checking_3()

elif ch==5:

print("thank you")

break

else:

print("ERROR 404")

def ticket_book():

mycon.commit()

print("Available trains")

g = "SELECT * FROM TRAIN_DETAILS"

mycursor.execute(g)

data = mycursor.fetchall()

Data=list(data)

a = ['tr_name', 'tr_no', 'from_station', 'to_station', 'AC1',


'AC2', 'AC3', 'SLEEPER']
print(tabulate(data, headers=a, tablefmt='psql'))

print("1010.RAJDHANI EXPRESS")

print("1020,VANDE BHARAT")

print("1030.JANSHATABDI")

print("1040.VIVEK EXPRESS")

x=input("enter the train no for more ticket details")

n=int(input("how many ticket booking"))

if n<=2:

if x=='1010':

g=delhi()

h= 'delhi'

c1='kanyakumari'

c2='rajdhani express'

elif x=='1020':

g=guj()

h='ahmedabad'

c1='delhi'
c2='vande bharat'

elif x=='1030':

g=blore()

h="bangalore"

c1='kolkata'

c2='janshatabadi'

elif x=='1040':

g=kerala()

h='thiruvanthapuram'

c1='delhi'

c2='garibradh'

elif x=='1050':

g=assam()

h='assam'

c1='kanyakumari'

c2='vivek express'

else:
print("invalid choice")

pnrno=random.randint(1000,3000)

for i in range(n):

b=input("enter the person name")

c=input("age")

s=input("gender")

s2="nsert into railway


values('{}','{}',{},'{}','{}','{}','{}','{}','{}','{}')".format(pnrno,b,c,x,
c2,s,g[1],c1,h,g[0])

mycursor.execute(s2)

print("booked")

print("Your PNR no is:", pnrno)

def delhi():

x = input("Enter your choice of


seat(AC1/AC2/AC3/SLEEPER): ")
if (x == "AC1"):

print('FIRST CLASS')

s = 4000

elif x == "AC2":

print('SECOND CLASS')

s = 5000

elif x == "AC3":

print('third CLASS')

s = 6000

elif x == "SLEEPER":

print('sleeper CLASS')

s = 8000

else:

print("Invalid")

s=0

print("The price for each ticket is", s, "\n")


return s, x

def guj():

x=input("enter ur choice of
seat(AC1/AC2/AC3/SLEEPER):")

if (x=="AC1"):

print('FIRST CLASS')

s=5000

elif(x=="AC2"):

print('SECOND CLASS')

s=7000

elif(x=="AC3"):

print('third CLASS')

s=8000

elif(x=="SLEEPER"):

print('sleeper CLASS')

s=9000

else:
print("invalid")

print("the prices for each ticket is",s,"\n")

return s,x

def blore():

x=input("enter ur choice of
seat(AC1/AC2/AC3/SLEEPER):")

if (x=="AC1"):

print('FIRST CLASS')

s=3000

elif(x=="AC2"):

print('SECOND CLASS')

s=4000

elif(x=="AC3"):

print('third CLASS')

s=5000
elif(x=="SLEEPER"):

print('sleeper CLASS')

s=6000

else:

print("invalid")

print("the prices for each ticket is",s,"\n")

return s,x

blore()

def kerala():

x=input("enter ur choice of
seat(AC1/AC2/AC3/SLEEPER):")

if (x=="AC1"):

print('FIRST CLASS')

s=500

elif(x=="AC2"):

print('SECOND CLASS')
s=600

elif(x=="AC3"):

print('third CLASS')

s=700

elif(x=="SLEEPER"):

print('sleeper CLASS')

s=900

else:

print("invalid")

print("the prices for each ticket is",s,"\n")

return s,x

def assam():

x=input("enter ur choice of
seat(AC1/AC2/AC3/SLEEPER):")

if (x=="AC1"):
print('FIRST CLASS')

s=1000

elif(x=="AC2"):

print('SECOND CLASS')

s=2000

elif(x=="AC3"):

print('third CLASS')

s=3000

elif(x=="SLEEPER"):

print('sleeper CLASS')

s=5000

else:

print("invalid")

print("the prices for each ticket is",s,"\n")

return s,x

def ticket_check():
print('1. yes')

print('2. no')

ch = int(input("Check a ticket?"))

if ch == 1:

pnrno = int(input('Enter your PNR no: '))

try:

s1 = "SELECT * FROM railways WHERE


pnr_no='{}'".format(pnrno)

mycursor.execute(s1)

data = mycursor.fetchall()

DATA = list(data)

a = ['PNRNO', 'PNAME', 'AGE', 'TR_NO', 'TR_NAME',


'GENDER', 'CLASS', 'FROM_STATION', 'TO_STATION',
'FARE']

print(tabulate(DATA, headers=a, tablefmt='psql'))

except:
print("Not exists")

elif ch == 2:

print("THANK YOU")

else:

print("Error")

def ticket_cancel():

print('1.yes')

print('2.no')

ch=int(input("cancel a ticket?"))

if ch==1:

pnrno=int(input('enter ur pnr no'))

s1="delete from railway where


pnr_no='{}'".format(pnrno)

mycursor.execute(s1)
print("cancelled")

elif ch==2:

print("THANK YOU")

else:

print("error")

def checking_2():

a = input("user name: ")

b = input("password: ")

try:

s1 = "select user_name from user_accounts where


password='{}'".format(b)

c1 = "select fname, lname from user_accounts where


password='{}'".format(b)

mycursor.execute(c1)

data1 = mycursor.fetchall()[0]

data1 = list(data1)

if data[0]==a:
print("is this ur acc")

s1 = "select user_name from user_accounts where


password='{}'".format(b)

c1 = "select fname, lname from user_accounts where


password='{}'".format(b)

mycursor.execute(s1)

data1 = mycursor.fetchall()[0]

data1 = list(data1)

data1=data1[0]+''+data1[1]

mycursor.execute(s1)

data=cursor.fetchall()[0]

data=list(data)

if data[0]==a:

x=['first name','last name','ph no','gender','dob','age']

s1="select fname,lname,phno,gender,dob,age from


user_account where password='{}'".format(b)

mycursor.execute(s1)
data=curosr.fetchall()[0]

data=list(data)

for i in range(0,6):

print(x[i],":::",data[i])

print('1.yes')

print('2.no')

vi=int(input("enter ur choice:"))

if vi==1:

b1="delete from user_accounts where


password='{}'".format(b)

mycursor.execute(b1)

return True

elif vi==2:

print("sry")

else:

print("error")

else:
print("account does not exist")

def checking_1():

mycon = mys.connect(host="localhost", user="root",


password="dev2006", database="project")

mycursor = mycon.cursor()

try:

f = input("first name: ")

l = input("last name: ")

n = f + '' + l

a = input("user name: ")

b = input("password: ")

c = input("re-enter your password: ")

ph = input("phone number: ")

gen = input("enter your gender: ")


print("enter dob")

d = input("DATE(DD):")

o = input("MONTH(MM):")

B = input("YEAR(YY):")

dob = d + '/' + o + '/' + B

age = input("your age: ")

if b == c:

c1 = "INSERT INTO user_accounts


VALUES('{}','{}','{}','{}','{}','{}','{}','{}')".format(

f, l, a, b, ph, gen, dob, age

mycursor.execute(c1)

mycon.commit()

print("Welcome", f, l)

return True

else:
print("Passwords do not match.")

return False

except mys.Error as e:

print("Error:", e)

return False

checking_1()

def checking():

a = input("user name: ")

b = input("password: ")

try:

s1 = "select user_name from user_accounts where


password='{}'".format(b)
c1 = "select fname, lname from user_accounts where
password='{}'".format(b)

mycursor.execute(c1)

data1 = mycursor.fetchall()[0]

data1 = list(data1)

data1 = data1[0] + ' ' + data1[1]

mycursor.execute(s1)

data2 = mycursor.fetchall()[0]

data2 = list(data2)

if data2[0] == a:

x = ["firstname", "lastname", "ph no", "gender",


"dob", "age"]

s2 = "select fname, lname, phno, gender, dob, age


from user_accounts where password='{}'".format(b)

mycursor.execute(s2)

data = mycursor.fetchall()

data1 = list(data)
print(tabulate(data, headers=x, tablefmt="psql"))

return True

else:

return False

except Exception as e:

print("Error:", e)

return False

def checking_3():

a = input("user name: ")

b = input("password: ")

try:

s1 = "select user_name from user_accounts where


password='{}'".format(b)

c1 = "select fname, lname from user_accounts where


password='{}'".format(b)

mycursor.execute(c1)

data1 = mycursor.fetchall()[0]
data1 = list(data1)

data1 = data1[0] + ' ' + data1[1]

mycursor.execute(s1)

data = mycursor.fetchall()[0]

data = list(data)

if data[0]==a:

x= ["firstname", "lastname", "ph no", "gender", "dob",


"age"]

s1= "select fname, lname, phno, gender, dob, age from


user_accounts where password='{}'".format(b)

mycursor.execute(s1)

data=cursor.fetchall()

data=list(data)

print(tabulate(data,headers=x,tablefmt="pmsql"))

else:

return False

except:
print("account does not exist")

You might also like