Ask coding questions

← Back to all posts
Dictionary to respond to a question (python)
h
rediar (90)

How would I use a dictionary to detect if someone said something, and respond?

Answered by CaptainAnon (48) [earned 5 cycles]
View Answer
Commentshotnewtop
CaptainAnon (48)
question2answer = {
  # Fill this in with question and answer combinations
  'question': 'answer'
}
question = input("What is your question? ")
if question in question2answer:
  print(question2answer['question'])
else:
  print("I'm not sure how to respond to that question.")

If you're happy to not use dictionaries you could also try using a neural network to do this (probably a recurrent neural network)!

rediar (90)

@CaptainAnon neural networks are way too much work. let me test this out.