Summary
Summary
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.
python
Copy code
class TripBookingSystem:
• Defines a class TripBookingSystem, which will handle all the functionality for trip bookings.
python
Copy code
def __init__(self):
self.regions = {
• 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"],
• 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 = {
• 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 = []
python
Copy code
self.transport_modes = {
"Flight": 5000,
"Train": 1500,
"Bus": 800,
• This defines a dictionary self.transport_modes with different modes of transport and their
corresponding cost per person.
Copy code
def display_regions(self):
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()
if region_choice == 0:
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())
selected_region = region_list[region_choice - 1]
return selected_region
else:
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
destinations = self.regions[selected_region]
print(f"{i}. {destination}")
• Displays the available destinations within the selected region and prompts the user to select
one by number.
python
Copy code
selected_destination = destinations[dest_choice - 1]
return selected_destination
else:
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
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
print("\nBudget Options:")
• Displays the available budget options (High, Medium, Low) for the user to select.
python
Copy code
if budget_choice == 1:
budget_type = "High"
elif budget_choice == 2:
budget_type = "Medium"
elif budget_choice == 3:
budget_type = "Low"
else:
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
• 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)
• 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":
total_budget *= 0.9
total_budget *= 0.85
python
Copy code
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
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
else:
return total_budget
Mock Payment:
python
Copy code
if not self.select_payment_method(total_budget):
return
• 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
if confirmation.lower() == 'yes':
self.bookings.append({
"booking_id": booking_id,
"destination": selected_destination,
"user_name": user_name,
"status": "Booked",
})
else:
• Confirms the booking and generates a random booking ID. The booking details are stored in
the self.bookings list.
Feedback Collection:
python
Copy code
print(f"Thank you for your feedback, {user_name}! You rated your trip to {selected_destination}
{rating} stars.")
else:
• 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:
if search_criteria == "1":
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
found = False
if booking['user_name'].lower() == user_name.lower():
found = True
if not found:
else:
else:
Cancel Booking:
python
Copy code
def cancel_booking(self):
if self.bookings:
booking_to_cancel = None
if booking['booking_id'] == booking_id:
booking_to_cancel = booking
break
if booking_to_cancel:
self.bookings.remove(booking_to_cancel)
else:
else:
python
Copy code
def run(self):
while True:
print("0. Exit")
• 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)
if transport_mode is None:
continue
self.mock_payment(budget)
elif choice == 2:
self.search_bookings()
elif choice == 3:
self.cancel_booking()
elif choice == 4:
self.collect_feedback(user_name, selected_destination)
elif choice == 0:
break
else:
• 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.
This code provides a complete interactive system for booking a trip in India.
4o mini