Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

If I am trying to get responses like I say "Hello" and get a random response in return (from the code below) how would I make this work based off of what I say like if I were to say "what is your name" and want a response from a name list instead Can I pull that off with a Dict?

import random 

responseHello = [

"Hi!",

"Hello!",

"How can i help you?",

]

responseDict = {

                "hello" : "responseHello"

                }

h = input("say Hello:")

if h = responseDict["hello"]

 print(responseHello)

So, as shown here (I know that bottom half certainly isn't right I just tried it) what would I have to do in order to get my input to cause a different response?. I am so sorry if this doesn't make sense, I just learned of the dictionary command today and am trying to figure it out. any help is greatly appreciated! (I know I have to try following some tutorial for chatbots but every time I do TensorFlow doesn't work at all)

1 Answer

0 votes
by (36.8k points)

Change if statement as below and it should work.

import random

if h in resoponseDict:

  print(random.choice(responseHello))

Edit: get random element in response Hello

If you are a beginner and want to know more about Data Science the do check out the Data Science course

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...