Professional Documents
Culture Documents
def dfs(graph,initial,goal):
stack=[(initial,[initial])]
visited = set()
while stack:
node, path = stack.pop()
if node == goal:
return path
return None
graph={ 'A':['B','C'],
'B':['D','E'],
'C':['F','G'],
'D':['H','I'],
'E':[],
'F':['K'],
'G':[],
'H':[],
'I':[],
'K':[]}
print(f"path is : {dfs(graph,'A','G')}")
while queue:
node, path = queue.popleft()
if node == goal:
return path
return None
graph={ 'A':['B','C'],
'B':['D','E'],
'C':['F','G'],
'D':['H','I'],
'E':[],
'F':['K'],
'G':[],
'H':[],
'I':[],
'K':[]}
initial_node='A'
goal_node='G'
result_path = BFS(graph,initial_node,goal_node)
print(f"path is : {result_path}")
if f_prime > 0:
x += step_size
else:
break
return x
x0 = 1
max_x = hill_climbing(f, x0)
print(f"Maximum found at x = {max_x:.4f}")
print(f"Function value at maximum: {f(max_x):.4f}")
In [2]: # 7 10 22 b
# pip install nltk
import nltk
from nltk.chat.util import Chat, reflections
chatbot_responses = [ [ r"hello|hi|hey",
["Hello!" , "Hi Buddy" , "Hii" , "Hey" , "Hey man"]
],
[ r"what is your name|what is your name?|your name|ur
["You called me Assistant" , "ChatBot" , "I don't h
],
[ r"Good Morning|Morning",
["You Look Gorgeous :-) Good Morning" , " Very Good
],
[ r"Bye|bai|Good Bye",
["Bye! see you later..." , "'ll be back ?" ,"bye","
]
]
chatbot = Chat(chatbot_responses, reflections)
print("hello! How can I help you?..... \n say 'exit' for end the conversati
while True:
user_input = input("YOU -> ")
if user_input.lower() == "exit":
print(" Bye ")
break
response = chatbot.respond(user_input)
print("BOT :",response)
if user_i.lower() == "exit":
print("Bye")
break
response = chatbot.respond(user_i)
print("BOT : ",response)
In [ ]: