AI: Assignment No.
6 – Expert System (Help Desk Management for Travelling)
#Input
class TravelExpertSystem:
def __init__(self):
self.knowledge_base = {
"destinations": {
"paris": {
"description": "Paris is the capital of France known for its art, fashion, and
culture.",
"attractions": ["Eiffel Tower", "Louvre Museum", "Champs-Elysées"],
"price": 500,
"currency": "EUR",
"food": ["Croissants", "Escargot", "Macarons"],
"language": "French",
"clothing": "Casual and stylish",
"sports": ["Football", "Tennis", "Cycling"]
},
"tokyo": {
"description": "Tokyo is the capital of Japan known for its technology and
history.",
"attractions": ["Tokyo Tower", "Shibuya Crossing", "Senso-ji"],
"price": 800,
"currency": "JPY",
"food": ["Sushi", "Ramen", "Tempura"],
"language": "Japanese",
"clothing": "Comfortable and modest",
"sports": ["Sumo Wrestling", "Baseball", "Karate"]
},
"rome": {
1
"description": "Rome is the capital of Italy known for its ancient history and
architecture.",
"attractions": ["Colosseum", "Vatican City", "Trevi Fountain"],
"price": 600,
"currency": "EUR",
"food": ["Pizza", "Pasta", "Gelato"],
"language": "Italian",
"clothing": "Elegant and casual",
"sports": ["Football", "Cycling", "Tennis"]
},
"london": {
"description": "London is the capital of England known for its history and
culture.",
"attractions": ["Big Ben", "London Eye", "Buckingham Palace"],
"price": 700,
"currency": "GBP",
"food": ["Fish and Chips", "Full English Breakfast", "Pies"],
"language": "English",
"clothing": "Casual and versatile",
"sports": ["Football", "Cricket", "Tennis"]
},
"new_york": {
"description": "New York City is known for its skyscrapers, Broadway shows,
and diverse culture.",
"attractions": ["Statue of Liberty", "Central Park", "Times Square"],
"price": 900,
"currency": "USD",
"food": ["Bagels", "Pizza", "Hot Dogs"],
"language": "English",
"clothing": "Urban and trendy",
2
"sports": ["Basketball", "Baseball", "American Football"]
},
"sydney": {
"description": "Sydney is the largest city in Australia known for its beautiful
beaches and vibrant culture.",
"attractions": ["Sydney Opera House", "Bondi Beach", "Harbour Bridge"],
"price": 850,
"currency": "AUD",
"food": ["BBQ", "Meat Pies", "Pavlova"],
"language": "English",
"clothing": "Casual and comfortable",
"sports": ["Rugby", "Cricket", "Soccer"]
},
"dubai": {
"description": "Dubai is a city in the UAE known for luxury shopping, modern
architecture, and nightlife.",
"attractions": ["Burj Khalifa", "Dubai Mall", "Palm Jumeirah"],
"price": 1200,
"currency": "AED",
"food": ["Hummus", "Shawarma", "Falafel"],
"language": "Arabic",
"clothing": "Smart casual with modesty",
"sports": ["Camel Racing", "Dune Bashing", "Golf"]
},
"cape_town": {
"description": "Cape Town is a city in South Africa known for its stunning
landscapes and rich history.",
"attractions": ["Table Mountain", "Cape of Good Hope", "Robben Island"],
"price": 800,
"currency": "ZAR",
3
"food": ["Braaivleis", "Bunny Chow"],
"language": "Afrikaans, English, Xhosa",
"clothing": "Casual and comfortable",
"sports": ["Rugby", "Cricket", "Soccer"]
},
"istanbul": {
"description": "Istanbul is a city in Turkey known for its historic sites and
delicious cuisine.",
"attractions": ["Hagia Sophia", "Blue Mosque", "Grand Bazaar"],
"price": 750,
"currency": "TRY",
"food": ["Kebabs", "Baklava", "Turkish Delight"],
"language": "Turkish",
"clothing": "Modest and respectful",
"sports": ["Football", "Basketball", "Wrestling"]
},
"bangkok": {
"description": "Bangkok is the capital of Thailand known for temples, street life,
and diverse food.",
"attractions": ["Grand Palace", "Wat Arun", "Chatuchak Market"],
"price": 700,
"currency": "THB",
"food": ["Pad Thai", "Tom Yum Goong", "Mango Sticky Rice"],
"language": "Thai",
"clothing": "Light and comfortable",
"sports": ["Muay Thai", "Football", "Badminton"]
},
"rio_de_janeiro": {
"description": "Rio is a Brazilian city known for beaches, Carnival, and
landmarks.",
4
"attractions": ["Christ the Redeemer", "Copacabana", "Sugarloaf Mountain"],
"price": 850,
"currency": "BRL",
"food": ["Feijoada", "Churrasco"],
"language": "Portuguese",
"clothing": "Casual and colorful",
"sports": ["Football", "Volleyball"]
},
"moscow": {
"description": "Moscow is the capital of Russia known for history and culture.",
"attractions": ["Red Square", "Kremlin", "St. Basil's Cathedral"],
"price": 700,
"currency": "RUB",
"food": ["Borscht", "Pelmeni", "Blini"],
"language": "Russian",
"clothing": "Warm and layered",
"sports": ["Ice Hockey", "Football", "Figure Skating"]
}
}
def get_destination_info(self, destination):
destination = [Link]()
if destination in self.knowledge_base["destinations"]:
info = self.knowledge_base["destinations"][destination]
return (
f"Description: {info['description']}\n"
f"Attractions: {', '.join(info['attractions'])}\n"
f"Price: {info['price']} {info['currency']}\n"
5
f"Food: {', '.join(info['food'])}\n"
f"Language: {info['language']}\n"
f"Clothing: {info['clothing']}\n"
f"Sports: {', '.join(info['sports'])}"
)
else:
return "Sorry, we don't have information about that destination."
def get_low_cost_city(self):
city = min(self.knowledge_base["destinations"].items(), key=lambda x: x[1]["price"])
return f"The lowest cost city is {city[0].replace('_', ' ').title()} at {city[1]['price']}
{city[1]['currency']}."
def get_high_cost_city(self):
city = max(self.knowledge_base["destinations"].items(), key=lambda x: x[1]["price"])
return f"The highest cost city is {city[0].replace('_', ' ').title()} at {city[1]['price']}
{city[1]['currency']}."
def get_famous_food_places(self, food_name):
food_name = food_name.lower()
results = []
for city, info in self.knowledge_base["destinations"].items():
if any(food_name in [Link]() for food in [Link]("food", [])):
[Link]([Link]('_', ' ').title())
if results:
return f"Famous foods:\n{food_name.title()} in {', '.join(results)}"
return "Sorry, we couldn't find any destinations with that food."
def get_city_sports(self, city):
city_key = [Link]().replace(" ", "_")
6
if city_key in self.knowledge_base["destinations"]:
sports = self.knowledge_base["destinations"][city_key].get("sports", [])
return f"Popular sports in {[Link]()}: {', '.join(sports)}"
return "Sorry, we couldn't find that city."
def get_city_currency(self, city):
city_key = [Link]().replace(" ", "_")
if city_key in self.knowledge_base["destinations"]:
currency = self.knowledge_base["destinations"][city_key].get("currency")
return f"The currency of {[Link]()} is {currency}."
return "Sorry, we couldn't find that city."
def run(self):
print("Welcome to the Travel Expert System!")
print("\nAsk about a city or type:")
print("- 'low cost city'")
print("- 'high cost city'")
print("- 'famous food <food name>'")
print("- 'popular sports in <city>'")
print("- 'currency of <city>'")
print("Enter 'exit' to quit:")
while True:
user_input = input("> ").strip().lower()
if user_input == "exit":
print("Goodbye!")
break
elif user_input == "low cost city":
print("Travel Agent:", self.get_low_cost_city())
7
elif user_input == "high cost city":
print("Travel Agent:", self.get_high_cost_city())
elif user_input.startswith("famous food"):
food = user_input.replace("famous food", "").strip()
if food:
print("Travel Agent:", self.get_famous_food_places(food))
else:
print("Please specify a food name, e.g., 'famous food sushi'")
elif user_input.startswith("popular sports in"):
city = user_input.replace("popular sports in", "").strip()
if city:
print("Travel Agent:", self.get_city_sports(city))
else:
print("Please specify a city, e.g., 'popular sports in Tokyo'")
elif user_input.startswith("currency of"):
city = user_input.replace("currency of", "").strip()
if city:
print("Travel Agent:", self.get_city_currency(city))
else:
print("Please specify a city, e.g., 'currency of Rome'")
else:
print("Travel Agent:", self.get_destination_info(user_input))
def main():
expert_system = TravelExpertSystem()
expert_system.run()
if __name__ == "__main__":
main()
8
#Output
(base) PS C:\Users\Nakshatra Shinde\OneDrive\Desktop\work\Internship> python
Assign6_AI.py
Welcome to the Travel Expert System!
Ask about a city or type:
- 'low cost city'
- 'high cost city'
- 'famous food <food name>'
- 'popular sports in <city>'
- 'currency of <city>'
Enter 'exit' to quit:
> paris
Travel Agent: Description: Paris is the capital of France known for its art, fashion, and
culture.
Attractions: Eiffel Tower, Louvre Museum, Champs-Elysées
Price: 500 EUR
Food: Croissants, Escargot, Macarons
Language: French
Clothing: Casual and stylish
Sports: Football, Tennis, Cycling
> low cost city
Travel Agent: The lowest cost city is Paris at 500 EUR.
> high cost city
Travel Agent: The highest cost city is Dubai at 1200 AED.
> famous food Pizza
Travel Agent: Famous foods:
Pizza in Rome, New York
> popular sports in rome
Travel Agent: Popular sports in Rome: Football, Cycling, Tennis
9
> currency of london
Travel Agent: The currency of London is GBP.
> exit
Goodbye!
10