SlideShare a Scribd company logo
1
Experiment No. : 01
Experiment Name : Write a Prolog program for addition of two numbers in Artificial Intelligence.
Objective : To find the summation of two numbers.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read X , Y
Set S to X+Y
Write S
Code :
% Prolog program for addition of two numbers------------
% Alamgir, CSE, JUST
go:- write('Enter first number : '), read(X),nl,
write('Enter second number : '), read(Y),nl,
sum(X,Y).
sum(X,Y):-
S is X+Y,
write('Summation of the two given number is : '), write(S)
Input :
go.
Enter first number : 100.
Enter second number : 200.
Output :
Summation of the two given number is : 300
2
Experiment No. : 02
Experiment Name : Write a Prolog program for addition & multiplication of two numbers in Artificial
Intelligence.
Objective : To find the addition & multiplication of two numbers.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read X , Y
Set S to X+Y
Set M to X*Y
Write S,M
Code :
% Prolog program for addition and multplication--------
% Alamgir, CSE, JUST
go:- write('Enter first number : '),read(X),nl,
write('Enter second number : '),read(Y),nl,
addmul(X,Y).
addmul(X,Y):-
S is X+Y,
M is X*Y,
write('Addition of the two number is : '),write(S),nl,
write('Multiplication of the two number is : '),write(M).
Input:
go.
Enter first number : 20.
Enter second number : 10.
Output :
Addition of the two number is : 30
Multiplication of the two number is : 200
3
Experiment No. : 03
Experiment Name : Write a Prolog program for finding the sum of all numbers in a given list in Artificial
Intelligence.
Objective : To find the sum of all numbers in a given list.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read all numbers
Add number and set to Result
Write Result
Code :
% Prolog program for find the sum of all numbers in a given list-------
% Alamgir, CSE, JUST
list([H|T],Result):-
listhelper(T,H,Result).
listhelper([],Acc,Acc).
listhelper([H|T],Acc,Result):-
Nacc is H+Acc,
listhelper(T,Nacc,Result).
Input: list([12,23,4,5,10,23,45],Result).
Output : Result = 122
4
Experiment No. : 04
Experiment Name : Write a Prolog program for comparing Character and String in Artificial Intelligence.
Objective : To compare character and String.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read two string
Compare Strings
Write Result
Code :
% Alamgir, CSE, JUST
predicates
start
comp_str(string,string)
comp_char(char,string)
goal
clearwindow,
start.
clauses
start:-
comp_str("abcd","dcab"),
write("equal"),nl.
start:-
write("not equal"),nl.
comp_str(Str1,Str2):-
Str1 <> "",
frontchar(Str1,Char1,Rest1),
comp_char(Char1,Str2),
comp_str(Rest1,Str2).
comp_str(Str1,Str2):-
Str1 = "".
comp_str(Str1,Str2):-
fail.
5
comp_char(Char1,Str2):-
frontchar(Str2,Char2,Rest2),
Char1 <> Char2,
Rest2 <> "",
comp_char(Char1,Rest2).
comp_char(Char1,Str2):-
frontchar(Str2,Char2,Rest2),
Char1 = Char2.
comp_char(Char1,Str2):-
fail.
Input : No input.
Output : equal
6
Experiment No. : 05
Experiment Name : Write a Prolog program to determine whether a element in a member of list in Artificial
Intelligence.
Objective : To determine whether a element in a member or not in a given list .
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read list of elemnets
Read the element
Check the element in the list or not
If exist set s to “Found”
Else set s to “Not Found”
Write s
Code :
% PROLOG PROGRAM TO DETERMINE WHETHER A ELEMENT IS A MEMBER OF LIST
% Alamgir, CSE, JUST
list=integer*
findnum(integer,list).
findnum(X,[]):-
write('The number is Not Found in the list.').
findnum(X,[X|Tail]):-
write('The number is Found in the list.').
findnum(X,[Y|Tail]):-
findnum(X,Tail).
Input : findnum(3,[1,2,3,4,5,6,7,8,10,11,12]).
Output : The number is Found in the list.
7
Experiment No. : 06
Experiment Name : Write a Prolog program to find sublists of the given list in Artificial Intelligence.
Objective : To find sublists of the given list.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read list of elemnets
Read the sublist
Check the sublist in the list or not
If exist set s to YES
Else set s to Not
Write s
Code :
% Alamgir, CSE, JUST
name = symbol
namelist = name*
predicates
sublist(namelist,namelist)
clauses
sublist([],[]).
sublist([First|Rest],[First|Sub]):-
sublist(Rest,Sub).
sublist([_|Rest],Sub):-
sublist(Rest,Sub).
Input : sublist([a,b,c],X).
Output :
X=["a","b","c"] ;
X=["a","b"] ;
X=["a","c"] ;
X=["a"] ;
X=["b","c"];
X=["b"] ;
X=["c"] ;
X=[]
8
Experiment No. : 07
Experiment Name : Write a prolog program for murder my story in Artificial Intelligence.
Objective : To find the murder of my story.
Software and Tools : GNU-Prolog Console, Notepad++.
Code :
% Alamgir, CSE, JUST
predicates
% pair(symbol,symbol)
iskiller(symbol,symbol)
male(symbol)
female(symbol)
isvictim(symbol)
not_at_bar(symbol,symbol)
not_at_beach(symbol,symbol)
not_alone(symbol)
twin(symbol,symbol)
younger(symbol,symbol)
child(symbol)
clauses
male(husband).
male(brother).
male(son).
female(alice).
female(daughter).
twin(brother,alice).
twin(son,daughter).
child(son).
child(daughter).
not_alone(
not_alone(alice).
not_alone(brother).
not_alone(X):-
9
child(X),child(Y)
not_at_beach(husband,alice).
not_at_beach(son,daughter).
not_at_bar(son,daughter).
not_at_bar(husband,alice).
not_at_bar(X,Y):-
male(X),male(Y).
not_at_bar(X,Y):-
female(X),female(Y).
isvictim(X):-
twin(X,Y),not(iskiller(Y,X)).
isvictim(X):-
twin(Y,X),not(iskiller(Y,X)).
younger(son,alice).
younger(son,husband).
younger(daughter,alice).
younger(daughter,husband).
iskiller(X,Y):-
not(alone(X)),
younger(X,Y),
not(not_at_beach(X,Y)),
not(not_at_bar(X,Y)).
Input : younger(son,alice).
Output : Yes
10
Experiment No. : 08
Experiment Name : Write a prolog program to reverse a list in Artificial Intelligence.
Objective : To reverse a given list.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read list of elemnets
Function for reverse
Set Result to reverse list
Write Result
Code :
% prolog program for reverse a given list------
% Alamgir, CSE, JUST
list([H|T],Result):-
reverselist(T, [H], Result).
reverselist([], Acc, Acc).
reverselist([H|T], Acc, Result):-
reverselist(T, [H|Acc], Result).
Input : list([3,5,6,7,8,12,34,120,22],Result).
Output : Result = [22,120,34,12,8,7,6,5,3]
11
Experiment No. : 09
Experiment Name : Write a prolog program to find the permutation of the given list in Artificial Intelligence.
Objective : To find the permutation of the given list.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read list of elemnets
Function for permutation is permute
Set Result p
Write p
Code :
% Alamgir, CSE, JUST
% PROLOG PROGRAM TO FIND THE PERMUTATION OF THE GIVEN LIST
% domains
list = symbol*
%predicates
permute(list,list).
del(symbol,list,list).
%clauses
del(X,[X|L1],L1).
del(X,[Y|L1],[Y|L2]):-
del(X,L1,L2).
permute([],[]).
permute(L,[X|P]):-
del(X,L,L1),
permute(L1,P).
Input : permute([a,b,c],P).
Output :
P=["a","b","c"];
P=["a","c","b"];
P=["b","a","c"];
P=["b","c","a"];
P=["c","a","b"];
P=["c","b","a"];
12
Experiment No. : 10
Experiment Name : Write a prolog program to find last item of the list in Artificial Intelligence.
Objective : To find the last item of the list.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read list of elemnets
Function for check element from first to last
Set X to last elemtnt
Write X
Code :
% Last item of a given list.....
% Alamgir, CSE, JUST
namelist = symbol*
lastd(namelist,symbol).
lastd([Head],X):-
X = Head.
lastd([_|Tail],X):-
lastd(Tail,X).
Input : lastd([a,b,c,d,e,f,g,h,I,j,k],X).
Output : X = k
13
Experiment No. : 12
Experiment Name : Write a prolog program to determine the greatest common divisor of two positive integer
numbers in Artificial Intelligence.
Objective : To determine the greatest common divisor of two positive integer numbers.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read X,Y
Function gcd (X,Y)
Set Result into X
Write X
Code :
% Prolog program for finding GCD of the two given number
% Alamgir Hossain, CSE, JUST
go:- write('Enter the first number : '),read(X),nl,
write('Enter the second number : '),read(Y),nl,
gcd(X,Y).
gcd(X,Y):-
X=Y,
write('GCD of the two given numbers is : '),write(X);
X=0,write('GCD of the two given numbers is : '),write(Y);
Y=0,write('GCD of the two given numbers is : '),write(X);
Y>X,Y1 is Y-X,gcd(X,Y1);
X>Y,Y1 is X-Y,gcd(Y1,Y).
Input :
go.
Enter the first number : 24.
Enter the second number : 3.
Output : GCD of the two given numbers is : 3
14
Experiment No. : 13
Experiment Name : Write a prolog program that stores information about your family, and will answer queries
about relationships in Artificial Intelligence.
Objective : To stores information about my family, and will answer queries about relationships.
Software and Tools : GNU-Prolog Console, Notepad++.
Code :
% Prolog program that store information about my family
% Alamgir, CSE, JUST
% Facts
father(mosiur, sharmin).
father(mosiur, rawshanara).
father(mosiur, alamgir).
father(mosiur, rahim).
father(auncle, liza).
father(auncle, robin).
father(robin, abid).
father(robin, snigdho).
father(sumon, apu).
mother(morium, sharmin).
mother(morium, alamgir).
mother(morium, rahim).
mother(aunty, liza).
mother(aunty, robin).
mother(sharmin, abid).
mother(sharmin, snigdho).
mother(rawshanara, apu).
% Rules-------
parent(X, Y) :- father(X, Y).
parent(X, Y) :- mother(X, Y).
grandfather(X, Y) :- father(X, Z), parent(Z, Y).
grandmother(X, Y) :- mother(X, Z), parent(Z, Y).
mama(X, Y) :- mother(X, Z), father(Z, Y).
15
huswife(X, Y) :- father(X, Z), mother(Y, Z).
brothersistertr(Y, Z) :- father(X, Y), father(X, Z).
mamavagne(Z, Y) :- father(X, Z),grandfather(X, Y).
Input : parent(X, Y).
Output :
X = mosiur
Y = sharmin ? ;
X = mosiur
Y = rawshanara ? ;
X = mosiur
Y = alamgir ? ;
X = mosiur
Y = rahim ? ;
16
Experiment No. : 14
Experiment Name : Write a prolog program to print a Fibonacci series in Artificial Intelligence.
Objective : To print a Fibonacci series up to n numbers.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read N
Function Fibonacci for the Fibonacci series
Write Result
Code :
% Prolog program for printing fibonacci series upto n numbers------
go:-
write('Enter a number : '),read(N),nl,
write('Fibonacci series for '),write(N),write(' elements is : '),nl,
A is 0,
B is 1,
write(A),write(' '),write(B),write(' '),
fibonacci(N,A,B).
fibonacci(N,A,B):-
(
N<2, write('Complete');
C is A+B,
write(C),write(' , '),
D is B,
E is C,
N1 is N-1, fibonacci(N1,D,E)
).
Input : go.
Enter a number : 10.
Output :
Fibonacci series for 10 elements is :
0 1 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , Complete
17
Experiment No. : 15
Experiment Name : Write a prolog program to calculate the factorial of a number using recursion in Artificial
Intelligence.
Objective : To calculate the factorial of a number using recursion.
Software and Tools : GNU-Prolog Console, Notepad++.
Pseudo code :
Read N
Repeat function fact and multiple N by N-1
Set result into F
Write F
Code :
% Alamgir, CSE, JUST
fact(0,1).
fact(N,F):-
(
N>0 ->
(
N1 is N-1,
fact(N1,F1),
F is N*F1
);
write('N should be greater than 0.')
).
Input : fact(8,R).
Output : R = 40320

More Related Content

What's hot

Python GUI Programming
Python GUI ProgrammingPython GUI Programming
Python GUI Programming
RTS Tech
 
Heaps
HeapsHeaps
Pattern matching
Pattern matchingPattern matching
Pattern matching
shravs_188
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
mandlapure
 
CLR AND LALR PARSER
CLR AND LALR PARSERCLR AND LALR PARSER
CLR AND LALR PARSER
Akila Krishnamoorthy
 
Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star search
Hema Kashyap
 
Fractional Knapsack Problem
Fractional Knapsack ProblemFractional Knapsack Problem
Fractional Knapsack Problem
harsh kothari
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
Rushdi Shams
 
First order logic
First order logicFirst order logic
First order logic
Megha Sharma
 
Boyer moore algorithm
Boyer moore algorithmBoyer moore algorithm
Boyer moore algorithm
AYESHA JAVED
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
Dattatray Gandhmal
 
Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Code
sanchi29
 
Unit 1 chapter 1 Design and Analysis of Algorithms
Unit 1   chapter 1 Design and Analysis of AlgorithmsUnit 1   chapter 1 Design and Analysis of Algorithms
Unit 1 chapter 1 Design and Analysis of Algorithms
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
String matching algorithms
String matching algorithmsString matching algorithms
String matching algorithms
Ashikapokiya12345
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
smruti sarangi
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
Madhu Bala
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocks
Jothi Lakshmi
 
String matching algorithm
String matching algorithmString matching algorithm
String matching algorithm
Alokeparna Choudhury
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Kiran K
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
wahab khan
 

What's hot (20)

Python GUI Programming
Python GUI ProgrammingPython GUI Programming
Python GUI Programming
 
Heaps
HeapsHeaps
Heaps
 
Pattern matching
Pattern matchingPattern matching
Pattern matching
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
 
CLR AND LALR PARSER
CLR AND LALR PARSERCLR AND LALR PARSER
CLR AND LALR PARSER
 
Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star search
 
Fractional Knapsack Problem
Fractional Knapsack ProblemFractional Knapsack Problem
Fractional Knapsack Problem
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
First order logic
First order logicFirst order logic
First order logic
 
Boyer moore algorithm
Boyer moore algorithmBoyer moore algorithm
Boyer moore algorithm
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Code
 
Unit 1 chapter 1 Design and Analysis of Algorithms
Unit 1   chapter 1 Design and Analysis of AlgorithmsUnit 1   chapter 1 Design and Analysis of Algorithms
Unit 1 chapter 1 Design and Analysis of Algorithms
 
String matching algorithms
String matching algorithmsString matching algorithms
String matching algorithms
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocks
 
String matching algorithm
String matching algorithmString matching algorithm
String matching algorithm
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
 

Similar to Lab report for Prolog program in artificial intelligence.

Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfsolution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
parthp5150s
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
Python basic
Python basicPython basic
Python basic
Saifuddin Kaijar
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
BAINIDA
 
Compiler design lab
Compiler design labCompiler design lab
Compiler design lab
ilias ahmed
 
Loops in Python
Loops in PythonLoops in Python
Loops in Python
Arockia Abins
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
rajatxyz
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
sagar414433
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
sagar414433
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
vsssuresh
 
Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)
Pedro Rodrigues
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
Vishal Singh
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
Mahmud Hasan Tanvir
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a Pythonist
Raji Engg
 
paython practical
paython practical paython practical
paython practical
Upadhyayjanki
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
gkgaur1987
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
gekiaruj
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
Matt Harrison
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
Andrei Tomoroga
 

Similar to Lab report for Prolog program in artificial intelligence. (20)

Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfsolution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Python basic
Python basicPython basic
Python basic
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
Compiler design lab
Compiler design labCompiler design lab
Compiler design lab
 
Loops in Python
Loops in PythonLoops in Python
Loops in Python
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a Pythonist
 
paython practical
paython practical paython practical
paython practical
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 

More from Alamgir Hossain

Malware Detection Approaches using Data Mining Techniques.pptx
Malware Detection Approaches using Data Mining Techniques.pptxMalware Detection Approaches using Data Mining Techniques.pptx
Malware Detection Approaches using Data Mining Techniques.pptx
Alamgir Hossain
 
5 nested if in c with proper example
5 nested if in c with proper example5 nested if in c with proper example
5 nested if in c with proper example
Alamgir Hossain
 
4. decision making and some basic problem
4. decision making and some basic problem4. decision making and some basic problem
4. decision making and some basic problem
Alamgir Hossain
 
3. user input and some basic problem
3. user input and some basic problem3. user input and some basic problem
3. user input and some basic problem
Alamgir Hossain
 
2. introduction of a c program
2. introduction of a c program2. introduction of a c program
2. introduction of a c program
Alamgir Hossain
 
1. importance of c
1. importance of c1. importance of c
1. importance of c
Alamgir Hossain
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
Alamgir Hossain
 
Report on student-faculty document sharing android project
Report on student-faculty document sharing android projectReport on student-faculty document sharing android project
Report on student-faculty document sharing android project
Alamgir Hossain
 
A lab report on modeling and simulation with python code
A lab report on modeling and simulation with python codeA lab report on modeling and simulation with python code
A lab report on modeling and simulation with python code
Alamgir Hossain
 
Lab report on to plot efficiency of pure and slotted aloha in matlab a data c...
Lab report on to plot efficiency of pure and slotted aloha in matlab a data c...Lab report on to plot efficiency of pure and slotted aloha in matlab a data c...
Lab report on to plot efficiency of pure and slotted aloha in matlab a data c...
Alamgir Hossain
 
Digital signal Processing all matlab code with Lab report
Digital signal Processing all matlab code with Lab report Digital signal Processing all matlab code with Lab report
Digital signal Processing all matlab code with Lab report
Alamgir Hossain
 
Microsoft Teams
Microsoft TeamsMicrosoft Teams
Microsoft Teams
Alamgir Hossain
 

More from Alamgir Hossain (12)

Malware Detection Approaches using Data Mining Techniques.pptx
Malware Detection Approaches using Data Mining Techniques.pptxMalware Detection Approaches using Data Mining Techniques.pptx
Malware Detection Approaches using Data Mining Techniques.pptx
 
5 nested if in c with proper example
5 nested if in c with proper example5 nested if in c with proper example
5 nested if in c with proper example
 
4. decision making and some basic problem
4. decision making and some basic problem4. decision making and some basic problem
4. decision making and some basic problem
 
3. user input and some basic problem
3. user input and some basic problem3. user input and some basic problem
3. user input and some basic problem
 
2. introduction of a c program
2. introduction of a c program2. introduction of a c program
2. introduction of a c program
 
1. importance of c
1. importance of c1. importance of c
1. importance of c
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
 
Report on student-faculty document sharing android project
Report on student-faculty document sharing android projectReport on student-faculty document sharing android project
Report on student-faculty document sharing android project
 
A lab report on modeling and simulation with python code
A lab report on modeling and simulation with python codeA lab report on modeling and simulation with python code
A lab report on modeling and simulation with python code
 
Lab report on to plot efficiency of pure and slotted aloha in matlab a data c...
Lab report on to plot efficiency of pure and slotted aloha in matlab a data c...Lab report on to plot efficiency of pure and slotted aloha in matlab a data c...
Lab report on to plot efficiency of pure and slotted aloha in matlab a data c...
 
Digital signal Processing all matlab code with Lab report
Digital signal Processing all matlab code with Lab report Digital signal Processing all matlab code with Lab report
Digital signal Processing all matlab code with Lab report
 
Microsoft Teams
Microsoft TeamsMicrosoft Teams
Microsoft Teams
 

Recently uploaded

How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 

Recently uploaded (20)

How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 

Lab report for Prolog program in artificial intelligence.

  • 1. 1 Experiment No. : 01 Experiment Name : Write a Prolog program for addition of two numbers in Artificial Intelligence. Objective : To find the summation of two numbers. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read X , Y Set S to X+Y Write S Code : % Prolog program for addition of two numbers------------ % Alamgir, CSE, JUST go:- write('Enter first number : '), read(X),nl, write('Enter second number : '), read(Y),nl, sum(X,Y). sum(X,Y):- S is X+Y, write('Summation of the two given number is : '), write(S) Input : go. Enter first number : 100. Enter second number : 200. Output : Summation of the two given number is : 300
  • 2. 2 Experiment No. : 02 Experiment Name : Write a Prolog program for addition & multiplication of two numbers in Artificial Intelligence. Objective : To find the addition & multiplication of two numbers. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read X , Y Set S to X+Y Set M to X*Y Write S,M Code : % Prolog program for addition and multplication-------- % Alamgir, CSE, JUST go:- write('Enter first number : '),read(X),nl, write('Enter second number : '),read(Y),nl, addmul(X,Y). addmul(X,Y):- S is X+Y, M is X*Y, write('Addition of the two number is : '),write(S),nl, write('Multiplication of the two number is : '),write(M). Input: go. Enter first number : 20. Enter second number : 10. Output : Addition of the two number is : 30 Multiplication of the two number is : 200
  • 3. 3 Experiment No. : 03 Experiment Name : Write a Prolog program for finding the sum of all numbers in a given list in Artificial Intelligence. Objective : To find the sum of all numbers in a given list. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read all numbers Add number and set to Result Write Result Code : % Prolog program for find the sum of all numbers in a given list------- % Alamgir, CSE, JUST list([H|T],Result):- listhelper(T,H,Result). listhelper([],Acc,Acc). listhelper([H|T],Acc,Result):- Nacc is H+Acc, listhelper(T,Nacc,Result). Input: list([12,23,4,5,10,23,45],Result). Output : Result = 122
  • 4. 4 Experiment No. : 04 Experiment Name : Write a Prolog program for comparing Character and String in Artificial Intelligence. Objective : To compare character and String. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read two string Compare Strings Write Result Code : % Alamgir, CSE, JUST predicates start comp_str(string,string) comp_char(char,string) goal clearwindow, start. clauses start:- comp_str("abcd","dcab"), write("equal"),nl. start:- write("not equal"),nl. comp_str(Str1,Str2):- Str1 <> "", frontchar(Str1,Char1,Rest1), comp_char(Char1,Str2), comp_str(Rest1,Str2). comp_str(Str1,Str2):- Str1 = "". comp_str(Str1,Str2):- fail.
  • 5. 5 comp_char(Char1,Str2):- frontchar(Str2,Char2,Rest2), Char1 <> Char2, Rest2 <> "", comp_char(Char1,Rest2). comp_char(Char1,Str2):- frontchar(Str2,Char2,Rest2), Char1 = Char2. comp_char(Char1,Str2):- fail. Input : No input. Output : equal
  • 6. 6 Experiment No. : 05 Experiment Name : Write a Prolog program to determine whether a element in a member of list in Artificial Intelligence. Objective : To determine whether a element in a member or not in a given list . Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read list of elemnets Read the element Check the element in the list or not If exist set s to “Found” Else set s to “Not Found” Write s Code : % PROLOG PROGRAM TO DETERMINE WHETHER A ELEMENT IS A MEMBER OF LIST % Alamgir, CSE, JUST list=integer* findnum(integer,list). findnum(X,[]):- write('The number is Not Found in the list.'). findnum(X,[X|Tail]):- write('The number is Found in the list.'). findnum(X,[Y|Tail]):- findnum(X,Tail). Input : findnum(3,[1,2,3,4,5,6,7,8,10,11,12]). Output : The number is Found in the list.
  • 7. 7 Experiment No. : 06 Experiment Name : Write a Prolog program to find sublists of the given list in Artificial Intelligence. Objective : To find sublists of the given list. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read list of elemnets Read the sublist Check the sublist in the list or not If exist set s to YES Else set s to Not Write s Code : % Alamgir, CSE, JUST name = symbol namelist = name* predicates sublist(namelist,namelist) clauses sublist([],[]). sublist([First|Rest],[First|Sub]):- sublist(Rest,Sub). sublist([_|Rest],Sub):- sublist(Rest,Sub). Input : sublist([a,b,c],X). Output : X=["a","b","c"] ; X=["a","b"] ; X=["a","c"] ; X=["a"] ; X=["b","c"]; X=["b"] ; X=["c"] ; X=[]
  • 8. 8 Experiment No. : 07 Experiment Name : Write a prolog program for murder my story in Artificial Intelligence. Objective : To find the murder of my story. Software and Tools : GNU-Prolog Console, Notepad++. Code : % Alamgir, CSE, JUST predicates % pair(symbol,symbol) iskiller(symbol,symbol) male(symbol) female(symbol) isvictim(symbol) not_at_bar(symbol,symbol) not_at_beach(symbol,symbol) not_alone(symbol) twin(symbol,symbol) younger(symbol,symbol) child(symbol) clauses male(husband). male(brother). male(son). female(alice). female(daughter). twin(brother,alice). twin(son,daughter). child(son). child(daughter). not_alone( not_alone(alice). not_alone(brother). not_alone(X):-
  • 10. 10 Experiment No. : 08 Experiment Name : Write a prolog program to reverse a list in Artificial Intelligence. Objective : To reverse a given list. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read list of elemnets Function for reverse Set Result to reverse list Write Result Code : % prolog program for reverse a given list------ % Alamgir, CSE, JUST list([H|T],Result):- reverselist(T, [H], Result). reverselist([], Acc, Acc). reverselist([H|T], Acc, Result):- reverselist(T, [H|Acc], Result). Input : list([3,5,6,7,8,12,34,120,22],Result). Output : Result = [22,120,34,12,8,7,6,5,3]
  • 11. 11 Experiment No. : 09 Experiment Name : Write a prolog program to find the permutation of the given list in Artificial Intelligence. Objective : To find the permutation of the given list. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read list of elemnets Function for permutation is permute Set Result p Write p Code : % Alamgir, CSE, JUST % PROLOG PROGRAM TO FIND THE PERMUTATION OF THE GIVEN LIST % domains list = symbol* %predicates permute(list,list). del(symbol,list,list). %clauses del(X,[X|L1],L1). del(X,[Y|L1],[Y|L2]):- del(X,L1,L2). permute([],[]). permute(L,[X|P]):- del(X,L,L1), permute(L1,P). Input : permute([a,b,c],P). Output : P=["a","b","c"]; P=["a","c","b"]; P=["b","a","c"]; P=["b","c","a"]; P=["c","a","b"]; P=["c","b","a"];
  • 12. 12 Experiment No. : 10 Experiment Name : Write a prolog program to find last item of the list in Artificial Intelligence. Objective : To find the last item of the list. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read list of elemnets Function for check element from first to last Set X to last elemtnt Write X Code : % Last item of a given list..... % Alamgir, CSE, JUST namelist = symbol* lastd(namelist,symbol). lastd([Head],X):- X = Head. lastd([_|Tail],X):- lastd(Tail,X). Input : lastd([a,b,c,d,e,f,g,h,I,j,k],X). Output : X = k
  • 13. 13 Experiment No. : 12 Experiment Name : Write a prolog program to determine the greatest common divisor of two positive integer numbers in Artificial Intelligence. Objective : To determine the greatest common divisor of two positive integer numbers. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read X,Y Function gcd (X,Y) Set Result into X Write X Code : % Prolog program for finding GCD of the two given number % Alamgir Hossain, CSE, JUST go:- write('Enter the first number : '),read(X),nl, write('Enter the second number : '),read(Y),nl, gcd(X,Y). gcd(X,Y):- X=Y, write('GCD of the two given numbers is : '),write(X); X=0,write('GCD of the two given numbers is : '),write(Y); Y=0,write('GCD of the two given numbers is : '),write(X); Y>X,Y1 is Y-X,gcd(X,Y1); X>Y,Y1 is X-Y,gcd(Y1,Y). Input : go. Enter the first number : 24. Enter the second number : 3. Output : GCD of the two given numbers is : 3
  • 14. 14 Experiment No. : 13 Experiment Name : Write a prolog program that stores information about your family, and will answer queries about relationships in Artificial Intelligence. Objective : To stores information about my family, and will answer queries about relationships. Software and Tools : GNU-Prolog Console, Notepad++. Code : % Prolog program that store information about my family % Alamgir, CSE, JUST % Facts father(mosiur, sharmin). father(mosiur, rawshanara). father(mosiur, alamgir). father(mosiur, rahim). father(auncle, liza). father(auncle, robin). father(robin, abid). father(robin, snigdho). father(sumon, apu). mother(morium, sharmin). mother(morium, alamgir). mother(morium, rahim). mother(aunty, liza). mother(aunty, robin). mother(sharmin, abid). mother(sharmin, snigdho). mother(rawshanara, apu). % Rules------- parent(X, Y) :- father(X, Y). parent(X, Y) :- mother(X, Y). grandfather(X, Y) :- father(X, Z), parent(Z, Y). grandmother(X, Y) :- mother(X, Z), parent(Z, Y). mama(X, Y) :- mother(X, Z), father(Z, Y).
  • 15. 15 huswife(X, Y) :- father(X, Z), mother(Y, Z). brothersistertr(Y, Z) :- father(X, Y), father(X, Z). mamavagne(Z, Y) :- father(X, Z),grandfather(X, Y). Input : parent(X, Y). Output : X = mosiur Y = sharmin ? ; X = mosiur Y = rawshanara ? ; X = mosiur Y = alamgir ? ; X = mosiur Y = rahim ? ;
  • 16. 16 Experiment No. : 14 Experiment Name : Write a prolog program to print a Fibonacci series in Artificial Intelligence. Objective : To print a Fibonacci series up to n numbers. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read N Function Fibonacci for the Fibonacci series Write Result Code : % Prolog program for printing fibonacci series upto n numbers------ go:- write('Enter a number : '),read(N),nl, write('Fibonacci series for '),write(N),write(' elements is : '),nl, A is 0, B is 1, write(A),write(' '),write(B),write(' '), fibonacci(N,A,B). fibonacci(N,A,B):- ( N<2, write('Complete'); C is A+B, write(C),write(' , '), D is B, E is C, N1 is N-1, fibonacci(N1,D,E) ). Input : go. Enter a number : 10. Output : Fibonacci series for 10 elements is : 0 1 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , Complete
  • 17. 17 Experiment No. : 15 Experiment Name : Write a prolog program to calculate the factorial of a number using recursion in Artificial Intelligence. Objective : To calculate the factorial of a number using recursion. Software and Tools : GNU-Prolog Console, Notepad++. Pseudo code : Read N Repeat function fact and multiple N by N-1 Set result into F Write F Code : % Alamgir, CSE, JUST fact(0,1). fact(N,F):- ( N>0 -> ( N1 is N-1, fact(N1,F1), F is N*F1 ); write('N should be greater than 0.') ). Input : fact(8,R). Output : R = 40320