Bus Booking System
Code:
# Bus Ticket Booking Mini Project with Price Calculation
fares = {
("Chennai", "Kovai"): 400,
("Trichy", "Salem"): 350,
("Salem", "Chennai"): 410,
("Chennai", "KanyaKumari"): 500
}
def book_ticket():
print("=== Bus Ticket Booking System ===")
print("\nAvailable Routes:")
for i, (route, price) in enumerate(fares.items(), 1):
print(f"{i}. {route[0]} → {route[1]} : ₹{price}")
source = input("\nEnter Source: ")
destination = input("Enter Destination: ")
if (source, destination) not in fares:
print(" Sorry, no bus available for this route.")
return
price_per_seat = fares[(source, destination)]
num_seats = int(input("Enter number of seats: "))
passengers = []
for i in range(num_seats):
print(f"\nEnter details for Passenger {i+1}:")
name = input("Name: ")
age = int(input("Age: "))
gender = input("Gender (M/F): ")
passengers.append({"Name": name, "Age": age, "Gender": gender})
total_price = num_seats * price_per_seat
print(f"\nTicket Price per seat: ₹{price_per_seat}")
print(f"Total Price for {num_seats} seat(s): ₹{total_price}")
print("\nPayment Methods:\n1. Credit Card\n2. UPI\n3. Cash")
choice = int(input("Choose payment method (1-3): "))
if choice == 1:
card_no = input("Enter Card Number: ")
print(" Payment successful using Credit Card ending with", card_no[-4:])
elif choice == 2:
upi_id = input("Enter UPI ID: ")
print(" Payment successful using UPI ID:", upi_id)
elif choice == 3:
print("Payment received in Cash.")
else:
print("Invalid choice. Booking failed!")
return
print("\n=== ️ Booking Confirmed ===")
print(f"From: {source} → To: {destination}")
print(f"Total Seats: {num_seats}")
print(f"Fare per Seat: ₹{price_per_seat}")
print(f"Total Fare: ₹{total_price}")
print("\nPassenger Details:")
for p in passengers:
print(f"- {p['Name']} ({p['Age']} yrs, {p['Gender']})")
print("\n Have a safe journey!")
book_ticket()
Output:

Comments
Post a Comment