Galgotias College of Engineering &
Technology
Master of Computer Applications – 3rd Semester
Artificial Intelligence Lab Practical
KCA 351
Section – A
Submitted By: Submitted
To:
Dr. Nripendra Kr
Singh
Index
Exp. Experiment Date of Signature
No. Exp.
1 Installation of python and basic operations
(Creating a Simple ChatBot)
2 Write of program to solve 4 Queens
problem
3 Write a program to solve breadth first
search
4 Write a program to solve depth first
search
5 Write a program to solve best first search
6 Write a program to solve TSP
7 Write a program to solve water jug
problem
8 Write a program to solve K-Means
Clustering
9 Write a program to solve Monkey Banana
problem
10 Write a program to solve Tower of Hanoi
Experiment No. - 1
Problem Statement: Installation of python and basic operations (Creating a Simple ChatBot).
Solutions:
Steps for installing python:
Step 1: Get the Python installer. You can find it by going to python.org and electing Windows
in the Download tab.
Step 2: Choose the latest stable release.
Step 3: Find the installer file that matches your machine’s specs.
Step 4: Download and run this file. Check the box Add Python 3.8 to PATH (which tells the
command line where to find the Python interpreter). Then click Install Now.
Step 5: Click Close to finish this process.
To access your Python installation, click on the Start button, choose Programs, and expand
Python 3.8.
Code for Chatbot
# Basic Chatbot using Python
# Define a dictionary with some example questions and responses
responses = {
"hi": "Hello! How can I help you today?",
"hello": "Hi there! How can I assist you?",
"how are you": "I'm just a program, but thanks for asking!
How can I help?",
"what is your name": "I'm a chatbot created to assist you.",
"help": "Sure, I'm here to help! Please ask your question.",
"goodbye": "Goodbye! Have a nice day.",
"exit": "Thank you for chatting! Goodbye."
}
# Function to get a response
def get_response(user_input):
# Standardize input
user_input = user_input.lower()
# Look for the input in predefined responses
for key in responses.keys():
if key in user_input:
return responses[key]
# If the input is not recognized, respond accordingly
return "I'm sorry, I don't understand that. Could you please
rephrase?"
# Main program
def chatbot():
print("Chatbot: Hello! I am here to assist you. Type 'exit'
to end the chat.")
while True:
# Get input from the user
user_input = input("You: ")
# Exit condition
if user_input.lower() == "exit":
print("Chatbot: Goodbye!")
break
# Get response and print it
response = get_response(user_input)
print(f"Chatbot: {response}")
# Run the chatbot
chatbot()
Output
Experiment No. - 2
Problem Statement: Write of program to solve 4 Queens problem.
Solution: