Ai Lab Manual
Ai Lab Manual
DEPARTMENT OF AIMLDS
Vision:
To facilitate transformation of students into highly skilled, knowledgeable and
competent software professional focusing on ethical values and societal
commitment.
Mission:
To impart quality education to meet the needs of the industry and research in the field of
computer science and engineering.
To encourage an environment conductive to innovation, creativity, team spirit and
entrepreneurial leadership in Computer Science and Engineering.
To foster networking with Alumni, Software Industries, Institutes and other stakeholders
for effective interaction.
To practice and promote high standards of ethical values through societal commitment.
1. PEO1. Graduates will have solid foundation in fundamentals of computer science and
engineering required to solve computing problems and create innovative software products and
solutions for the real life problems.
2. PEO2. Graduates will have technical competence and skills to use modern and cost-effective
tools and technologies and have extensive and effective practical skills in computer science and
engineering to pursue a career as a computer engineer.
3. PEO3. Graduates will have attributes like professionals with world class academic excellence,
ethics, best practices, values, social concerns, lifelong learning and openness to other
international cultures to meet the global needs.
4. PEO4. Graduates will have managerial and entrepreneur skills with cross-cultural etiquettes,
leading to a sustainable competitive edge in R&D and meeting societal needs.
Program Outcomes
PO1 Engineeringknowledge:Applytheknowledgeofmathematics,science,engineeringfundamentals,and
an engineeringspecializationtothesolutionofcomplex engineering problems.
PO2 Problemanalysis:Identify,formulate,reviewresearchliterature,andanalyzecomplexengineeringproble
msreachingsubstantiatedconclusionsusingfirstprinciplesofmathematics,naturalsciences,andengineeri
ngsciences.
PO3 Design/developmentofsolutions:Design solutions for complex engineering problems and design
systemcomponentsorprocessesthatmeetthespecifiedneedswithappropriateconsiderationforthepublich
ealthandsafety,andthecultural,societal,andenvironmentalconsiderations.
PO4 Conductinvestigationsofcomplexproblems:Useresearch-
basedknowledgeandresearchmethodsincludingdesignofexperiments,analysisandinterpretationofdata,
andsynthesisoftheinformationtoprovidevalidconclusions.
PO5 Moderntoolusage:Create,select,andapplyappropriatetechniques,resources,andmodernengineeringan
dITtoolsincludingpredictionandmodelingtocomplexengineeringactivitieswithanunderstandingoftheli
mitations.
PO6 Theengineerandsociety:Applyreasoninginformedbythecontextualknowledgetoassesssocietal,health
,safety,legalandculturalissuesandtheconsequentresponsibilitiesrelevanttotheprofessionalengineering
practice.
PO7 Environmentandsustainability:Understandtheimpactoftheprofessionalengineeringsolutionsinsocie
talandenvironmentalcontexts,anddemonstratetheknowledgeof,andneedforsustainabledevelopment.
PO8 Ethics:Applyethicalprinciplesandcommittoprofessionalethicsandresponsibilitiesandnormsoftheengi
neeringpractice.
PO9 Individual and team work: Function effectively as an individual, and as a member or leader
indiverse teams, and in multi disciplinary settings.
PO10 Communication:Communicateeffectivelyoncomplexengineeringactivitieswiththeengineeringcomm
unityandwithsocietyatlarge,suchas,beingabletocomprehendandwriteeffectivereportsanddesigndocu
mentation,makeeffectivepresentations,andgiveandreceiveclearinstructions.
PO11 Projectmanagementandfinance:Demonstrateknowledgeandunderstandingoftheengineeringandma
nagementprinciplesandapplythesetoone’sownwork,asamemberandleaderinateam,tomanageprojectsa
ndinmultidisciplinaryenvironments.
PO12 Life-
longlearning:Recognizetheneedfor,andhavethepreparationandabilitytoengageinindependentandlife-
longlearninginthebroadestcontextoftechnologicalchange.
Program Specific Outcomes
PSO1 Domain Knowledge: An ability to understand, analyze and develop computer programs in the
areas related to Algorithms, System Software, Multimedia, Web Design, Big Data and Analytics
and Networking for efficient design of computer based systems of varying complexity to meet the
need of the software industry.
PSO2
1. Process Management: An Ability to organize and apply standard practices and strategies in
software product development by managing and monitoring the resources and safeguarding the
data.
ARTIFICIAL INTELLIGENCE LAB SYLLABUS
8 (a) Write a python program to remove punctuations from the given string. 26
(b) Write a python program to sort the sentence in alphabetical order.
10
Write a program to implement Tic-Tac-Toe game using python. 32
Program
Program
Exp. Experiments Specific
Outcomes
No. Outcomes
Attained
Attained
1 (a). Write a python program to print the multiplication
table for the given number. PO1,PO2,PO3
(b). Write a python program to check whether the PSO1
given number is prime or not.
(c) Write a python program to find factorial of the
given number.
2 Write a python program to implement simple PO1 PSO1
Chatbot.
3 (a) Write a python program to implement List
PO1,PO2 PSO1,PSO2
operations (Nested List, Length, Concatenation,
Membership, Iteration, Indexing and Slicing).
(b) Write a python program to implement List
methods (Add, Append, and Extend & Delete).
10
Write a program to implement Tic-Tac-Toe game
using python. PO1,PO2 PSO1,PSO2
4
ARTIFICIAL INTELLIGENCE LAB SYLLABUS
COURSE OBJECTIVES
1. Gain a historical perspective of AI and its foundations.
2. Become familiar with basic principles of AI toward problem solving, inference,
perception, knowledge representation, and learning.
3. Investigate applications of AI techniques in intelligent agents, expert systems, artificial
neural networks and other machine learning models.
4. Experience AI development tools such as an ‘AI language’, expert system shell, and/or
data mining tool.
5. Experiment with a machine learning model for simulation and analysis.
6. Explore the current scope, potential, limitations, and implications of intelligent systems.
COURSE OUTCOMES
Student will be able to;
1. Demonstrate fundamental understanding of the history of artificial intelligence (AI) and
its foundations.
2. Apply basic principles of AI in solutions that require problem solving, inference,
perception, knowledge representation, and learning.
3. Demonstrate awareness and a fundamental understanding of various applications of AI
techniques in intelligent agents, expert systems, artificial neural networks and other
machine learning models.
4. Demonstrate proficiency developing applications in an 'AI language', expert system
shell, or data mining tool.
5. Demonstrate proficiency in applying scientific method to models of machine learning.
6. Demonstrate an ability to share in discussions of AI, its current scope and limitations,
and societal implications.
5
EXPERIMENT-1
1.1 Name of the Experiment:
a) Write a python program to print the multiplication table for given number.
1.2 OBJECTIVE: a) To write a python program to print the multiplication table for
given number.
1.3 PROGRAM:
RESULT: Thus, the multiplication table for the given number is executed successfully and the output is verified.
1.2 OBJECTIVE: To write a python program to check whether the given number is prime or not?
1.3 PROGRAM:
RESULT: Thus, for the given number is the program is executed successfully and the output is verified.
1.3 PROGRAM:
fact=fact*i
print("Thenum=int(input("Enter a number\n"))
fact=1
if num<0:
elif num==0:
else:
for i in range(1,num+1):
factorial of",num,"is",fact)
output:---
Enter your number to get fatorial
5
The factorial of 5 is 120
RESULT: Thus, for the given number the factorial is executed successfully and the output is verified.
EXPERIMENT-2
pairs=[
[r'hi',['hii']],
chat=Chat(pairs,reflections)
chat.converse()
>hi
hii
>how are you
iam good
>where are you
im in ongole
responses = {
"hi": "Hello!",
def get_response(user_input):
if user_input in responses:
return responses[user_input]
else:
while True:
if user_input.lower() == 'bye':
print("ChatBot: Goodbye!")
break
response = get_response(user_input)
print("ChatBot:", response)
RESULT: Thus, for the chatbot program is executed successfully and the output is verified.
EXPERIMENT-3
3.2 OBJECTIVE: To write a python program to implement List operations (Nested List, Length,
Concatenation, Membership, Iteration, Indexing and Slicing).
9
3.3 PROGRAM:
L=['a','b',['cc','d',['eee','fff']],'g','h']
print(L[2])
print(L[2][2])
print(L[2][2][0])
print(L[-3])
my_list= [_ for _ in 'abcdefghi']
print("slicing",my_list[5:])
print("slicing",my_list[:4])
print(L[-3][-1])
print(L[-3][-1][-2])
print(len(L))
print(len(L[1]))
list1=[1,2,3,4]
list2=[5,6,7]
res=list1+list2
print(res)
l=[1,2,3]
print("2 contains in list",2 in l)
l=[1,2,3]
for i in range(0,len(l)):
print(l[i])
Output:--
['cc', 'd', ['eee', 'fff']]
['eee', 'fff']
eee
['cc', 'd', ['eee', 'fff']]
slicing ['f', 'g', 'h', 'i']
slicing ['a', 'b', 'c', 'd']
['eee', 'fff']
eee
5
1
[1, 2, 3, 4, 5, 6, 7]
2 contains in list True
1
2
3
RESULT: Thus, for the list operations are executed successfully and the output is
verified.
3.1 Name of the Experiment:
(b) Write a python program to implement List Methods(Add,Append and Extend &
Delete)?
a=[]
b=["value1","value2"]
append=input("Enter string to append")
a.append(append)
print(a)
a.extend(b)
print(a)
a.remove("value1")
print(a)
Output:--
Enter string to append 2
['2']
['2', 'value1', 'value2']
['2', 'value2']
RESULT: Thus, for the List methods are executed successfully and the output is verified .
EXPERIMENT-4
4.1 Name of the Experiment:
4.3 PROGRAM:
E={0,2,4,6,8};
N={1,2,3,4,5};
print("Union of E and N is",E|N)
print("Intersection of E and N is",E&N)
print("Difference of E and N is",E-N)
print("Symmetric difference of E and N is",E^N)
Output:-
E={0,2,4,6,8};
N={1,2,3,4,5};
print("Union of E and N is",E|N)
print("Intersection of E and N is",E&N)
print("Difference of E and N is",E-N)
print("Symmetric difference of E and N is",E^N)
RESULT: Thus, the program to illustrate the set operations is executed successfully and the output is verified.
4.1 Name of the Experiment:
b) Write a python program to generate Calendar for the given month and year.
4.2OBJECTIVE: To Write a python program to generate Calendar for the given month and year.
4.3 PROGRAM: 11
import calendar
yy=int(input("Input the year:"))
mm=int(input("Input the month:"))
print(calendar.month(yy,mm))
Output:--
Input the year: 2024
Input the month: 05
May 2024
Mo Tu We Th Fr Sa Su
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
RESULT: Thus, for the calendar for the given month and year is executed successfully and the output is verified.
4.1 Name of the Experiment:
4.3 PROGRAM:
Output:
Select operation.
1. Add
2. Subtract
3. Multiply
4. Divide
Enter choice (1/2/3/4): 1
Enter first number: 2
Enter second number: 5
2.0 + 5.0 = 7.0
Let's do next calculation? (Yes/no): Y
Enter choice (1/2/3/4): 2
Enter first number: 5
Enter second number: 8
5.0 - 8.0 = -3.0
Let's do next calculation? (Yes/no): Y
Enter choice (1/2/3/4): 3
Enter first number: 8
Enter second number: 5
8.0 * 5.0 = 40.0
Let's do next calculation? (Yes/no): Y
Enter choice (1/2/3/4): 4
Enter first number: 4
Enter second number: 2
4.0 / 2.0 = 2.0
RESULT: Thus, the program for the simple calculator is executed successfully and the output is verified.
EXPERIMENT-5
X = [[12,7,3],
[4 ,5,6],
[7 ,8,9]]
Y = [[5,8,1],
[6,7,3],
[4,5,9]]
result = [[0,0,0],
[0,0,0],
[0,0,0]]
for i in range(len(X)):
for j in range(len(X[0])):
result[i][j] = X[i][j] + Y[i][j]
for r in result:
print(r)
Output:--
[17, 15, 4]
[10, 12, 9]
RESULT: Thus, the matrix addition program is executed successfully and the output is verified.
5.1 Name of the Experiment:
5.3 PROGRAM:
X = [[12,7],
[4 ,5],
[3 ,8]]
result = [[0,0,0],
[0,0,0]]
for i in range(len(X)):
for j in range(len(X[0])):
result[j][i] = X[i][j]
for r in result:
print(r)
Output:--
[12, 4, 3]
14
[7, 5, 8]
RESULT: Thus, for the transpose of the given matrix is executed successfully and the output is verified.
EXPERIMENT-6
6.2 OBJECTIVE: To write a python program to implement Breadth First Search Traversal?
6.3 PROGRAM:
graph={
'5':['3','7'],
'3':['2','4'],
'7':['8'],
'2':[],
'4':['8'],
'8':[]
visited=[]
queue=[]
def bfs(visited,graph,node):
visited.append(node)
queue.append(node)
while queue:
m= queue.pop(0)
print(m,end="")
visited.append(neighbour)
queue.append(neighbour)
bfs(visited,graph,'5')
Output:--
RESULT: Thus, for the BFS Search Technique is executed successfully and the output is verified.
EXPERIMENT-7
7.1 Name of the Experiment:
7.3 PROGRAM:
if rno==2:
if y<3:
y=3
if rno==5:
if x>0:
x=0
if rno==6:
if y>0:
y=0
if rno==7:
if x+y>= 4 and y>0:
x,y=4,y-(4-x)
if rno==8:
if x+y>=3 and x>0:
x,y=x-(3-y),3
if rno==9:
if x+y<=4 and y>0:
x,y=x+y,0
if rno==10:
if x+y<=3 and x>0:
x,y=0,x+y
print("X =",x)
print("Y =",y)
if (x==2):
print(" The result is a Goal state")
break
Output:--
RESULT: Thus, the water jug problem is executed successfully and the output is verified.
EXPERIMENT-8
8.2 OBJECTIVE: To write a python program to remove punctuations from the given string.
.
8.3 PROGRAM:
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
my_str = "Heyyah!!!, My name is Sam ;)."
no_punct = ""
for char in my_str:
if char not in punctuations:
no_punct = no_punct + char
print(no_punct)
Output:--
8.3 PROGRAM:
words.sort()
print(word)
Output:--
RESULT: Thus, the program to sort the sentence in alphabetical order is executed successfully and the output is
verified.
EXPERIMENT-9
9.2 OBJECTIVE: To write a python program to implement Hangman game using python.
.
9.3 PROGRAM:
import time
time.sleep(1)
time.sleep(0.5)
#here we set the secret. You can select any word to play with. 18
word = ("secret")
#creates an variable with an empty value
guesses = ''
turns = 10
failed = 0
if char in guesses:
print (char,end=""),
else:
print ("_",end=""),
failed += 1
if failed == 0:
break
turns -= 1
# print wrong
print ("Wrong")
if turns == 0:
Output:
Start guessing...
______guess a character:s
s_____guess a character:r
s__r__guess a character:t
s__r_tguess a character:e
se_retguess a character:c
secretYou won
RESULT: Thus, the program to implement Hangman Game is executed successfully and the output is verified.
EXPERIMENT-10
10.2 OBJECTIVE: Write a python program to implement Tic-Tac-Toe game using python.
10.3 PROGRAM:
20
import random
currentPlayer = "X"
winner = None
gameRunning = True
# game board
def printBoard(board):
print("---------")
print("---------")
def playerInput(board):
if board[inp-1] == "-":
board[inp-1] = currentPlayer
else:
def checkHorizontle(board):
global winner
winner = board[0]
return True
return True
elif board[6] == board[7] == board[8] and board[6] != "-":
winner = board[6]
return True
def checkRow(board):
global winner
winner = board[0]
return True
winner = board[1]
return True
winner = board[3]
return True
def checkDiag(board):
global winner
winner = board[0]
return True
winner = board[2]
return True
def checkIfWin(board):
global gameRunning
if checkHorizontle(board):
printBoard(board)
22
print(f"The winner is {winner}!")
gameRunning = False
elif checkRow(board):
printBoard(board)
gameRunning = False
elif checkDiag(board):
printBoard(board)
gameRunning = False
def checkIfTie(board):
global gameRunning
printBoard(board)
print("It is a tie!")
gameRunning = False
# switch player
def switchPlayer():
global currentPlayer
if currentPlayer == "X":
currentPlayer = "O"
else:
currentPlayer = "X"
def computer(board):
position = random.randint(0, 8)
if board[position] == "-":
board[position] = "O"
23
switchPlayer()
while gameRunning:
printBoard(board)
playerInput(board)
checkIfWin(board)
checkIfTie(board)
switchPlayer()
computer(board)
checkIfWin(board)
checkIfTie(board)
Output:
-|-|-
---------
-|-|-
---------
-|-|-
-|O|-
---------
-|-|-
---------
X|-|-
O|O|-
---------
-|X|-
---------
X|-|-
24
Select a spot 1-9: 8
O|O|-
---------
-|X|O
---------
X|X|-
O|O|-
---------
-|X|O
---------
X|X|X
The winner is X!
O|O|-
---------
O|X|O
---------
X|X|X
The winner is X!
RESULT: Thus, the program to implement Tic-Tac Toe game is executed successfully and the output is verified.
25