My Blog

My WordPress Blog

My Blog

My WordPress Blog

Travel Planner

Simple Travel Planner in Python

class TravelPlanner:
def __init__(self):
    self.destinations = {}

def add_destination(self, name, activities):
    self.destinations[name] = activities

def view_destinations(self):
    print("Available Destinations:")
    for destination in self.destinations:
        print(f"- {destination}")
def create_itinerary(self, destination, budget):
    if destination not in self.destinations:
        print("Destination not found.")
        return
    
    activities = self.destinations[destination]
    itinerary = []
    
    print(f"\nCreating itinerary for {destination} with a budget of ${budget}:")
    
    for activity, cost in activities.items():
        if cost <= budget:
            itinerary.append(activity)
            budget -= cost
            print(f"Added: {activity} (${cost})")
    
    if not itinerary:
        print("No activities fit within the budget.")
    else:
        print("\nFinal Itinerary:")
        for item in itinerary:
            print(f"- {item}")
# Example Usage if __name__ == "__main__":
planner = TravelPlanner()

# Adding destinations and their activities
planner.add_destination("Paris", {
    "Eiffel Tower Visit": 25,
    "Louvre Museum": 15,
    "Seine River Cruise": 30,
    "Notre Dame Cathedral": 0,
    "Montmartre Tour": 10
})

planner.add_destination("New York", {
    "Statue of Liberty": 20,
    "Broadway Show": 100,
    "Central Park": 0,
    "Museum of Modern Art": 25,
    "Brooklyn Bridge Walk": 0
})

# Viewing available destinations
planner.view_destinations()

# Creating an itinerary
destination = input("\nEnter your destination: ")
budget = int(input("Enter your budget: "))

planner.create_itinerary(destination, budget)

How to Use the Code

  1. Add Destinations: You can add destinations and their associated activities with costs.
  2. View Destinations: The program displays all available destinations.
  3. Create Itinerary: Enter a destination and budget to generate a list of activities that fit within your budget.

Running the Code

You can run this code in any Python environment. Just copy and paste it into a .py file or directly into a Python interpreter.

Next Steps

  • Expand Activities: Include more detailed activity descriptions, timings, etc.
  • User Profiles: Allow users to save and load their travel preferences.
  • Web Integration: Create a web app using frameworks like Flask or Django for a more user-friendly interface.
Travel Planner

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top