Ai7 8
Ai7 8
PRACTICAL:-8
CODE:
from collections import defaultdict
print(capacity1, capacity2)
return True
if visited[(capacity1, capacity2)] == False:
print(capacity1, capacity2)
visited[(capacity1, capacity2)] = True
waterjugprolem(0, 0)
OUTPUT :
PRACTICAL:-7
CODE:
def createGraph(graph):
n = int(input("Enter no. nodes required:-"))
for _ in range(n):
node = input("enter nodes and connected nodes in following format:
a:b,c(here b and c are connected nodes)").split(":")
graph[node[0]] = node[1].split(",")
return graph
def bfs(graph,start,dest):
result = ["Path not found",list()]
visited = list()
queue = list()
queue.append(start)
visited.append(start)
while queue:
currentNode = queue.pop(0)
if(currentNode not in graph.keys() ):
continue
for node in graph[currentNode]:
if( node not in graph.keys() ):
continue
if(node==dest):
result[0] = "Reachable"
break
if(node not in visited):
visited.append(node)
queue.append(node)
result[1] = visited
return result
graph = dict()
graph = createGraph(graph)
start = input("point to start from:-")
end = input("point to reach upon:-")
result = bfs(graph,start,end)
print("Founded path is as follows",result[0])
print("Path traversal" ,result[1])
OUTPUT :
PRACTICAL:-3
CODE:
def chatbot():
print("\nwelcome to chat box. How may I help You?")
lst=["\nMovies","superhero,drama,thriller,comedy"]
while True:
user_input = input("\nYou: ")
if "movies" in user_input.lower():
print("\nChatbot: Sure, what kind of movie do you like to watch?")
a = input("\nYou: ")
print("\nWhat do you like about" + a + "?")
chatbot()
OUTPUT :