Bus ticket booking basic code using python
def getstopnum(s,details):
for q in details[2]:
if s in (details[2][q]).upper()+(details[2][q]).lower():
return int(q)
return None
def searchjn(jn):
flag=False
for i in journeys:
if jn==i:
return True
return False
def order(stops):
ordered={}
for i in range(len(stops)):
ordered[(i+1)]=stops[i]
return ordered
def assignstpfare():
global stpfare
for i in journeys:
for j in journeys[i][2]:
stpfare[journeys[i][2][j]]=0
def book(book_jn):
global bookn
global journeys
print("journey has stops:",journeys[book_jn][2])
bsa=input("Enter entry stop")
bsl=input("Enter leaving stop")
book_sa=getstopnum(bsa,journeys[book_jn])
book_sl=getstopnum(bsl,journeys[book_jn])
if book_sa is None or book_sl is None:
print("Invalid stop input!")
return
booker=input("Enter your name")
bookn_amt=abs(book_sl-book_sa)*charge+bookn["fee"]
print("Please pay Rs.",bookn_amt)
l=list(bookn[book_jn].keys())
n=l[-1]+1
bookn[book_jn][n]=booker
bookn['collectn']+=bookn_amt
print("Your trip has been confirmed!!\nHave a nice journey!!")
return
journeys={1:['pl-kty-kol-tvm',170,{1:'pala',2:'bharanangyanam',3:'kottayam',4:'Trivandrum'}],2:['pl-kty
ekm',170,{1:'pala',2:'bharanangyanam',3:'kottayam',4:'Ernakulam'}]}
emp_id={'1':"Rahul",'2':"nat",'3':'wendy'}
pw="123XXXtravels"
all_stops=[]
jn_wise_stop={}
for i in journeys:
l=list(journeys[i][2].values())
jn_wise_stop[i]=l
for j in l:
if j not in all_stops:
all_stops.append(j)
print("\t\tWelcome to XXX Travel Agency")
print("We offer services to the following stops")
for i in (all_stops):
print("\t",i)
print("We offer services the following trips")
for i in jn_wise_stop:
print("For journey ",i,", the stops are:")
for j in (all_stops):
print("\t",j)
charge=float(input("\n\nEnter min charge"))
stpfare={}
assignstpfare()
bookn={1:{1:["Jean",1,2],2:["Jen",3,2]},2:{1:["Jane",1,2]},"collectn":100,"fee":30}
acc=int(input("Access further functions for:\n1. Admin\n2. Employee\n3. Customer\n"))
if acc==1:
en_pw=input("Enter the password: ")
if en_pw==pw:
print('\t\tTransport Office: Registery of Bus Fares and Buses'.center(100))
print("1. Add new bus")
print("2. Assign employees to trip")
print("3. Search bus")
print('4. Print total fare of bus or stop')
print('5. Total fare collected from all buses')
print('6. Which ruote was most income generating')
print('7. Which stop was most income generating')
print("8. Total number of passengers using the transport facility")
print("9. Change rate or min charge")
print("10. Add new Employee")
print("11. See Bookings")
print("12. See all journeys")
print("13. Fire an Employee")
while True:
ch=int(input("Enter your choice of action: "))
#1-Add bus-done
if ch==1:
j=int(input('Enter Journey number: '))
print("For the journey number:",j)
dist=float(input("Enter total distance of travel"))
rut=input("Enter ruote of the bus using the codes for the depots")
stops = input("Enter the list of bus stops in order (comma-separated): ").split(',')
stops=order(stops)
bus=[rut,dist,stops]
journeys[j]=bus
print(journeys)
if ch==2:
#under 2(start trp)assign employee
jn=int(input("Enter Journey no. of the trip"))
if searchjn(jn):
print("Employee id: Employee\n",emp_id)
journeys[jn].append(emp_id[input("Enter employee id to assign to journey")])
else:
print("Invalid journey number!!")
elif ch==3:
journ=int(input("Enter journey number to search: "))
if searchjn(journ):
print("Details of journey ",journ,'is:',journeys[journ])
elif ch==4:
wannasee=input("Enter whether you want to know fare collected from a stop or a journey[stop/journey]: ")
if wannasee in "JOURNEYjourney":
sjn=int(input("Enter journey number to print total fare collected"))
print("Total fare collected from ",sjn,'is',journeys[sjn][3])
elif wannasee in 'stopSTOP':
ststp=int(input("Enter stop to print total fare collected"))
print("Total fare collected from ",ststp,'is',stpfare[ststp])
elif ch==5:
t=0
for i in journeys:
t+=journeys[i][3]
print("Total fare collected is: Rs.",t)
elif ch==7:
fmax=0
maxstp=""
for i in stpfare:
if fmax<stpfare[i]:
fmax=stpfare[i]
maxstp=i
print("Max income is generated from:",maxstp,"the amount collected is:",fmax)
elif ch==8:
passengers=0
for i in journeys:
passengers+=journeys[i][4]
print("Total number of passengers using the facility is: ",passengers)
elif ch==9:
charge=float(input("Enter new rate"))
elif ch==10:
e_id=input("Enter id of new employee")
nam=input("Enter new employee's name")
emp_id[e_id]=nam
print(emp_id)
elif ch==11:
print("Bookings:")
print(bookn)
print("Total Collection from bookings: Rs.",bookn["collectn"])
elif ch==12:
print("Journeys")
print(journeys)#json
continue_or_not=input("Do you want to continue? [y/n]")
if continue_or_not not in 'yY':
break
elif ch==13:
print(emp_id)
del_emp=input("Enter Employee id of person: ")
emp_id.pop[del_emp]
elif acc==2:
e_id=input("Enter your employee id: ")
if e_id in emp_id:
#under 2(start trp)-start fare collection
print("Bookings:")
print(bookn)
k=input("Enter 's' to start fare collection: ")
itotalfare=0
if k=='s':
jn=int(input("Enter Journey no. of the trip"))
if searchjn(jn):
pass_no=0
while True:
start=input("Enter entry stop: ")
sa=getstopnum(start,journeys[jn])
stop=input("Enter leaving stop: ")
sp=getstopnum(stop,journeys[jn])
ucharge="SORRY WRONG STOP"
if sa==None or sp ==None:
print("Stop not in trip!")
continue
else:
ucharge=(abs(sp-sa)+1)*charge
print(ucharge)
itotalfare+=ucharge
stpfare[start]+=ucharge
print("Ticket fare: Rs.",ucharge)
pass_no+=1
instruction=input("Enter 'end' to end fare collection")
if instruction.lower() == "end":
journeys[jn].append(itotalfare)
journeys[jn].append(pass_no)
print("collection: Rs.",itotalfare,"no. of passengers: ",pass_no)
break
else:
continue
else:
print("Invalid journey number!!")
elif acc==3:
print("Welcome once again to XXX Travel Agency")
print("We offer journeys in the following ruotes: ")
for i in journeys:
print("journey number:",i,'goes in the ruote: ',journeys[i][0])
y_or_n=input("Do you wish to book?[y/n]")
if y_or_n in 'Yy':
book_jn=int(input("Enter journey number to book: "))
if searchjn(book_jn):
book(book_jn)
print("Thank you for booking with us!")
else:
print("Uh oh! wrong journey number entered.\nTry Again",journeys)
book_jn=int(input("Enter journey number to book: "))
book(book_jn)
SAMPLE OUTPUT
Welcome to XXX Travel Agency
We offer services to the following stops
pala
bharanangyanam
kottayam
Trivandrum
Ernakulam
We offer services the following trips
For journey 1 , the stops are:
pala
bharanangyanam
kottayam
Trivandrum
Ernakulam
For journey 2 , the stops are:
pala
bharanangyanam
kottayam
Trivandrum
Ernakulam
Enter min charge1
Access further functions for:
1. Admin
2. Employee
3. Customer
1
Enter the password: 123XXXtravels
MENU
1. Add new bus
2. Assign employees to trip
3. Search bus
4. Print total fare of bus or stop
5. Total fare collected from all buses
6. Which ruote was most income generating
7. Which stop was most income generating
8. Total number of passengers using the transport facility
9. Change rate or min charge
10. Add new Employee
11. See Bookings
12. See all journeys
13. Fire an Employee
Enter your choice of action: 1
Enter Journey number: 55
For the journey number: 55
Enter total distance of travel348
Enter ruote of the bus using the codes for the depotstvm-kol-alp-ptn
Enter the list of bus stops in order (comma-separated): ['trivandrum','kollam','alapuzha','pala']
{1: ['pl-kty-kol-tvm', 170, {1: 'pala', 2: 'bharanangyanam', 3: 'kottayam', 4: 'Trivandrum'}], 2: ['pl-kty-ekm', 170, {1: 'pala', 2:
'bharanangyanam', 3: 'kottayam', 4: 'Ernakulam'}], 55: ['tvm-kol-alp-ptn', 348.0, {1: "['trivandrum'", 2: "'kollam'", 3: "'alapuzha'", 4:
"'pala']"}]}
Do you want to continue? [y/n]y
Enter your choice of action: 2
Enter Journey no. of the trip55
Employee id: Employee
{'1': 'Rahul', '2': 'nat', '3': 'wendy'}
Enter employee id to assign to journey1
Do you want to continue? [y/n]y
Enter your choice of action: 3
Enter journey number to search: 55
Details of journey 55 is: ['tvm-kol-alp-ptn', 348.0, {1: "['trivandrum'", 2: "'kollam'", 3: "'alapuzha'", 4: "'pala']"}, 'Rahul']
Do you want to continue? [y/n]y
Enter your choice of action: 4
Enter whether you want to know fare collected from a stop or a journey[stop/journey]: journey
Enter journey number to print total fare collected1
Comments
Post a Comment