CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2024
    Posts
    2

    Need Help in Finishing this Trip Planner Python code

    Is it possible to include more features in it such as advanced trip planning, API integrations, or user-specific preferences?

  2. #2
    Join Date
    Sep 2024
    Posts
    2

    Re: Need Help in Finishing this Trip Planner Python code

    Code:
    import datetime
    
    class TripPlannerChatbot:
        def __init__(self):
            self.destination = None
            self.start_date = None
            self.end_date = None
            self.activities = []
            self.budget = None
    
        def greet_user(self):
            print("Hi! I'm your Trip Planner Chatbot. I can help you plan your perfect vacation. Let's get started!")
    
        def ask_destination(self):
            self.destination = input("Where would you like to go on your trip? ")
            print(f"Great choice! {self.destination} sounds like a fantastic destination.")
    
        def ask_dates(self):
            start = input("When would you like to start your trip? (YYYY-MM-DD) ")
            end = input("When would you like to end your trip? (YYYY-MM-DD) ")
    
            try:
                self.start_date = datetime.datetime.strptime(start, "%Y-%m-%d")
                self.end_date = datetime.datetime.strptime(end, "%Y-%m-%d")
                if self.start_date >= self.end_date:
                    print("Oops! The end date should be after the start date. Let's try again.")
                    self.ask_dates()
                else:
                    print(f"Your trip is set from {self.start_date.strftime('%B %d, %Y')} to {self.end_date.strftime('%B %d, %Y')}.")
            except ValueError:
                print("Invalid date format. Please use YYYY-MM-DD format.")
                self.ask_dates()
    
        def ask_activities(self):
            print("What activities are you interested in? (Type 'done' when finished)")
            while True:
                activity = input("- ")
                if activity.lower() == 'done':
                    break
                self.activities.append(activity)
            if self.activities:
                print(f"Awesome! We'll plan for activities like: {', '.join(self.activities)}.")
            else:
                print("No activities added. You can still enjoy some free time during your trip!")
    
        def ask_budget(self):
            budget = input("What is your budget for this trip? (in USD) ")
    
            try:
                self.budget = float(budget)
                print(f"Your budget is set at ${self.budget:.2f}. We'll make sure to plan accordingly.")
            except ValueError:
                print("Please enter a valid number for the budget.")
                self.ask_budget()
    
        def summarize_trip(self):
            print("\nTrip Summary:")
            print(f"Destination: {self.destination}")
            print(f"Dates: {self.start_date.strftime('%B %d, %Y')} to {self.end_date.strftime('%B %d, %Y')}")
            if self.activities:
                print(f"Activities: {', '.join(self.activities)}")
            print(f"Budget: ${self.budget:.2f}")
    
        def start_planning(self):
            self.greet_user()
            self.ask_destination()
            self.ask_dates()
            self.ask_activities()
            self.ask_budget()
            self.summarize_trip()
    
    # Example usage
    if __name__ == "__main__":
        bot = TripPlannerChatbot()
        bot.start_planning()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured