Ask coding questions

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

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

Answered by CaptainAnon (133) [earned 5 cycles]
View Answer
CaptainAnon (133)
question2answer = {
  # Fill this in with question and answer combinations
  'question': 'answer'
question = input("What is your question? ")
if question in question2answer:
  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 (402)

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