Ai Experiment PDF Final
Ai Experiment PDF Final
Code:
def bfs(graph,n):
queue=[n]
visited=[n]
while queue:
x=queue.pop(0)
print(x,end=" ")
for i in graph[x]:
if i not in visited:
queue.append(i)
visited.append(i)
graph = {
'5' : ['3','7'],
'3' : ['2', '4'],
'7' : ['8'],
'2' : [],
'4' : ['8'],
'8' : []
}
bfs(graph,'5')
Output:
EXPERIMENT #2
Objective: Given two water jugs with capacities X and Y litres. Initially, both
the jugs are empty. Also given that there is an infinite amount of water available.
The jugs do not have markings to measure smaller quantities.
One can perform the following operations on the jug:
Input: X = 5, Y = 7, Z = 4
Algorithm:
Code:
print("JUG1\tJUG2")
pour(0, 0)
OUTPUT:
EXPERIMENT 3
Problem Statement: Write a python program to remove punctuations from the
given string.
Objective: Removing punctuations from the given string. Input: A string from
user.
Algorithm:
3. In each iteration, check if the character is a punctuation mark or not using the
membership test.
if char not in punctuation
4. Define an empty string to which add (concatenate) the character if it is not
punctuation.
CODE:-
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
no_punct = ""
print(no_punct).
OUTPUT:-
EXPERIMENT 4
Problem Statement: Write a python program to sort the sentence in alphabetical
order.
displayed.
words.sort()
print(word,end=" ")
OUTPUT:-