0% found this document useful (0 votes)
15 views12 pages

Summary

The document outlines the implementation of a TripBookingSystem class in Python, which facilitates trip bookings by allowing users to select regions, destinations, and budget options, while also managing itineraries and transport modes. It includes methods for generating itineraries, planning budgets, applying discounts, confirming bookings, collecting feedback, and searching or canceling bookings. The system is designed to provide a complete interactive experience for booking trips in India.

Uploaded by

haasinijv2008
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)
15 views12 pages

Summary

The document outlines the implementation of a TripBookingSystem class in Python, which facilitates trip bookings by allowing users to select regions, destinations, and budget options, while also managing itineraries and transport modes. It includes methods for generating itineraries, planning budgets, applying discounts, confirming bookings, collecting feedback, and searching or canceling bookings. The system is designed to provide a complete interactive experience for booking trips in India.

Uploaded by

haasinijv2008
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/ 12

Sure! Let me explain the code line by line.

1. Import Statements:

python

Copy code

import random

import datetime

• import random: This imports the random module to generate random numbers, which is
used later to generate a random booking ID.

• import datetime: This imports the datetime module, which is used to work with dates and
times, like recording the booking date and time.

2. TripBookingSystem Class Definition:

python

Copy code

class TripBookingSystem:

• Defines a class TripBookingSystem, which will handle all the functionality for trip bookings.

3. __init__ Method (Constructor):

python

Copy code

def __init__(self):

self.regions = {

"North": ["Delhi", "Shimla", "Manali", "Agra", "Amritsar"],

"South": ["Chennai", "Bangalore", "Hyderabad", "Kerala", "Pondicherry"],

"East": ["Kolkata", "Darjeeling", "Gangtok", "Shillong", "Bhubaneshwar"],

"West": ["Mumbai", "Goa", "Jaipur", "Udaipur", "Ahmedabad"],

"Central": ["Bhopal", "Indore", "Raipur", "Khajuraho", "Ujjain"]

• This initializes a dictionary self.regions that holds the regions and corresponding destinations
in India. Each region is mapped to a list of cities.

python

Copy code

self.itinerary = {

"Delhi": ["Red Fort", "India Gate", "Qutub Minar", "Lotus Temple", "Humayun's Tomb"],
"Agra": ["Taj Mahal", "Agra Fort", "Fatehpur Sikri"],

"Shimla": ["Mall Road", "Jakhoo Temple", "Kufri"],

"Manali": ["Rohtang Pass", "Solang Valley", "Hidimba Temple"],

• This initializes a dictionary self.itinerary that holds lists of popular places to visit in specific
cities. These are default itineraries for the selected destinations.

python

Copy code

self.budget_types = {

"High": lambda num_people, num_days: num_people * num_days * 3000, # Adjusted cost

"Medium": lambda num_people, num_days: num_people * num_days * 2000,

"Low": lambda num_people, num_days: num_people * num_days * 1200

• This defines a dictionary self.budget_types where each key corresponds to a budget type
(High, Medium, Low). The value is a lambda function (anonymous function) that calculates
the budget based on the number of people and days.

python

Copy code

self.bookings = []

• Initializes an empty list self.bookings to store the booking details later.

python

Copy code

self.transport_modes = {

"Flight": 5000,

"Train": 1500,

"Bus": 800,

"Car Rental": 2000

• This defines a dictionary self.transport_modes with different modes of transport and their
corresponding cost per person.

4. Methods for the TripBookingSystem Class:

Display Available Regions:


python

Copy code

def display_regions(self):

print("\nAvailable Regions to Explore :")

for idx, region in enumerate(self.regions.keys(), 1):

print(f"{idx}. {region}")

print("0. Exit")

• Displays a list of available regions (North, South, East, West, Central) to the user. The user
can select a region by its number or exit by selecting 0.

Select Region:

python

Copy code

def select_region(self):

self.display_regions()

region_choice = int(input("\nSelect a region by number (or 0 to exit): "))

if region_choice == 0:

print("Exiting the program. Safe travels!")

return None

• Prompts the user to select a region by entering a number. If 0 is selected, the program exits.

python

Copy code

region_list = list(self.regions.keys())

if 1 <= region_choice <= len(region_list):

selected_region = region_list[region_choice - 1]

print(f"\nYou selected: {selected_region}")

return selected_region

else:

print("Invalid choice! Try again.")

return None

• If the selected choice is valid (between 1 and the number of regions), it returns the selected
region. Otherwise, it asks the user to try again.

Select Destination:
python

Copy code

def select_destination(self, selected_region):

print(f"\nAvailable Destinations in {selected_region}:")

destinations = self.regions[selected_region]

for i, destination in enumerate(destinations, 1):

print(f"{i}. {destination}")

dest_choice = int(input("\nSelect a destination by number: "))

• Displays the available destinations within the selected region and prompts the user to select
one by number.

python

Copy code

if 1 <= dest_choice <= len(destinations):

selected_destination = destinations[dest_choice - 1]

print(f"\nYou selected: {selected_destination}")

return selected_destination

else:

print("Invalid choice! Try again.")

return None

• If the selected choice is valid, it returns the selected destination. Otherwise, it asks the user
to try again.

Generate Itinerary:

python

Copy code

def generate_itinerary(self, destination):

print(f"\nItinerary for {destination}:")

places_to_visit = self.itinerary.get(destination, ["Explore local attractions", "Relax and unwind"])

for place in places_to_visit:

print(f"- {place}")

• Generates an itinerary for the selected destination by listing out popular places to visit (if
available). If the destination is not in the itinerary, it lists default options.
Plan Budget:

python

Copy code

def plan_budget(self, selected_destination, transport_cost):

print("\nBudget Options:")

print("1. High ")

print("2. Medium ")

print("3. Low ")

• Displays the available budget options (High, Medium, Low) for the user to select.

python

Copy code

budget_choice = int(input("\nSelect a budget: "))

if budget_choice == 1:

budget_type = "High"

elif budget_choice == 2:

budget_type = "Medium"

elif budget_choice == 3:

budget_type = "Low"

else:

print("Invalid choice! Exiting...")

return None

• Prompts the user to select a budget option and assigns the corresponding budget type. If the
input is invalid, the function exits.

python

Copy code

print("\nEnter your travel details:")

num_people = int(input("Number of people: "))

num_days = int(input("Number of days: "))

• Prompts the user for the number of people and the number of days of the trip.

python

Copy code
base_budget = self.budget_types[budget_type](num_people, num_days)

transport_total = transport_cost * num_people

total_budget = base_budget + transport_total

• Calculates the base budget using the selected budget type and the travel details. It also
calculates the transport cost for all the people and adds it to the total budget.

python

Copy code

# Applying discounts

discount = 0

if budget_type == "Medium":

discount = 0.10 # 10% discount for Medium budget

total_budget *= 0.9

elif budget_type == "High":

discount = 0.15 # 15% discount for High budget

total_budget *= 0.85

• Applies discounts based on the budget type (Medium or High).

python

Copy code

print(f"\nDiscount Applied: {discount * 100}%")

print(f"Estimated Budget for {num_people} people for {num_days} days (including transport):
₹{total_budget:.2f}")

return total_budget

• Displays the applied discount and the total budget for the trip (including transport). Returns
the final total budget.

Apply Coupon:

python

Copy code

def apply_coupon(self, total_budget):

coupon_code = input("\nDo you have a coupon code? (Enter 'no' to skip): ")

if coupon_code.lower() != 'no':

if coupon_code == "DISCOUNT10":
total_budget *= 0.9 # 10% off for coupon DISCOUNT10

print("Coupon applied! You've received a 10% discount.")

elif coupon_code == "SUMMER20":

total_budget *= 0.8 # 20% off for coupon SUMMER20

print("Coupon applied! You've received a 20% discount.")

else:

print("Invalid coupon code!")

return total_budget

• Allows the user to apply a coupon code for an additional discount.

Mock Payment:

python

Copy code

def mock_payment(self, total_budget):

print("\n=== Payment Details ===")

print(f"Total Amount to Pay: ₹{total_budget:.2f}")

if not self.select_payment_method(total_budget):

return

input("Press Enter to proceed with the payment...")

print("Payment Successful! ")

• Displays the payment details and simulates the payment process. After the user selects a
payment method, the program proceeds with the payment.

Confirm Booking:

python

Copy code

def confirm_booking(self, selected_destination, user_name, budget):

confirmation = input(f"\nDo you want to confirm your booking for {selected_destination}?


(yes/no): ")

if confirmation.lower() == 'yes':

booking_id = random.randint(1000, 9999)

self.bookings.append({

"booking_id": booking_id,

"destination": selected_destination,
"user_name": user_name,

"status": "Booked",

"date": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

})

print(f"\nYour booking has been confirmed! Your Booking ID: {booking_id}")

else:

print("\nBooking not confirmed. Please try again later.")

• Confirms the booking and generates a random booking ID. The booking details are stored in
the self.bookings list.

Feedback Collection:

python

Copy code

def collect_feedback(self, user_name, selected_destination):

print("\nThank you for booking with us!")

rating = int(input("Please rate your experience (1 to 5 stars): "))

if 1 <= rating <= 5:

print(f"Thank you for your feedback, {user_name}! You rated your trip to {selected_destination}
{rating} stars.")

else:

print("Invalid rating! Please rate between 1 to 5.")

• Collects feedback from the user after the trip. The user rates the trip experience on a scale of
1 to 5.

Search Bookings:

python

Copy code

def search_bookings(self):

if self.bookings:

search_criteria = input("\nSearch by (1) Booking ID or (2) Name: ")

if search_criteria == "1":

booking_id = int(input("Enter the Booking ID: "))

for booking in self.bookings:

if booking['booking_id'] == booking_id:
print(f"Booking ID: {booking['booking_id']} | Name: {booking['user_name']} | Destination:
{booking['destination']} | Status: {booking['status']} | Date: {booking['date']}")

return

print("\nBooking ID not found!")

elif search_criteria == "2":

user_name = input("Enter the Name: ")

found = False

for booking in self.bookings:

if booking['user_name'].lower() == user_name.lower():

print(f"Booking ID: {booking['booking_id']} | Name: {booking['user_name']} | Destination:


{booking['destination']} | Status: {booking['status']} | Date: {booking['date']}")

found = True

if not found:

print("\nNo bookings found for the given name!")

else:

print("\nInvalid choice! Try again.")

else:

print("\nYou have no bookings yet!")

• Allows the user to search bookings by either Booking ID or Name.

Cancel Booking:

python

Copy code

def cancel_booking(self):

if self.bookings:

booking_id = int(input("\nEnter the Booking ID you want to cancel: "))

booking_to_cancel = None

for booking in self.bookings:

if booking['booking_id'] == booking_id:

booking_to_cancel = booking

break

if booking_to_cancel:
self.bookings.remove(booking_to_cancel)

print(f"\nBooking with ID {booking_id} has been successfully canceled!")

else:

print("\nBooking ID not found! Please check again.")

else:

print("\nYou have no bookings to cancel!")

• Allows the user to cancel a booking by entering the Booking ID.

Main Loop (run method):

python

Copy code

def run(self):

while True:

print("\n=== Trip Booking System ===")

print("1. Book a Trip")

print("2. Search Bookings")

print("3. Cancel Booking")

print("4. Provide Feedback")

print("0. Exit")

choice = int(input("\nEnter your choice: "))

• The run method contains a loop that displays the menu options and allows the user to
choose between booking a trip, searching bookings, canceling a booking, or providing
feedback.

python

Copy code

if choice == 1:

region = self.select_region()

if region is None:

break

destination = self.select_destination(region)

if destination is None:

continue
user_name = input("\nEnter your name: ")

self.generate_itinerary(destination)

transport_mode, transport_cost = self.select_transport_mode()

if transport_mode is None:

continue

budget = self.plan_budget(destination, transport_cost)

if budget is not None:

budget = self.apply_coupon(budget) # Apply coupon

self.mock_payment(budget)

self.confirm_booking(destination, user_name, budget)

elif choice == 2:

self.search_bookings()

elif choice == 3:

self.cancel_booking()

elif choice == 4:

user_name = input("Enter your name to provide feedback: ")

selected_destination = input("Enter the destination you visited: ")

self.collect_feedback(user_name, selected_destination)

elif choice == 0:

print("Exiting the program. Safe travels!")

break

else:

print("Invalid choice! Try again.")

• Based on the user's choice, the program calls the appropriate method to execute the desired
action. The loop keeps running until the user selects 0 to exit.

End of Class Definition


• The TripBookingSystem class handles the entire trip booking process, including region
selection, itinerary generation, transport mode, budgeting, payment, booking confirmation,
feedback collection, and even booking search and cancellation.

This code provides a complete interactive system for booking a trip in India.

4o mini

You might also like