Python 如何在一个列表中给变量自己的变量随机选择

Python 如何在一个列表中给变量自己的变量随机选择,python,Python,我正在尝试建立一个人工智能,你教你,你问问题,如果它不知道,它会问你,并给出一个答案,我只是不能让它对一个问题有多个答案 我尝试过嵌套列表,但随机选择一个列表很困难,我认为嵌套列表不对 quest=[] ans=[] loop=0 newword=['Oh, I dont know this!','Hmm Ive never heard of that.','idk','owo whats this?','Im still learning.'] running=True while runni

我正在尝试建立一个人工智能,你教你,你问问题,如果它不知道,它会问你,并给出一个答案,我只是不能让它对一个问题有多个答案

我尝试过嵌套列表,但随机选择一个列表很困难,我认为嵌套列表不对

quest=[]
ans=[]
loop=0
newword=['Oh, I dont know this!','Hmm Ive never heard of that.','idk','owo whats this?','Im still learning.']
running=True
while running==True:
  a=input('Ask a question')
  if a in quest:
    while loop<=len(quest):
      if a==quest[loop]:
        print(ans[loop])
        break
      else:
        loop=loop+1
  else:
    quest.append(a)
    b=input(newword[randint(0,4)]+' You tell me, '+a)
    ans.append(b)
quest=[]
ans=[]
循环=0
newword=[“哦,我不知道这个!”,“嗯,我从来没听说过这个。”,“idk”,“这是什么?”,“我还在学习。”
运行=真
运行时==True:
a=输入(‘提问’)
如果有人在寻找:

while loop我可能不理解这里的问题,但是像字典这样的东西不管用吗

dict = {}
dict["your question or reference to your question number"] = []
dict["your question or reference to your question number"].append(b)

你需要做的是将问题返回给人类,不管人工智能是否知道答案。如果它没有,它将学习它的第一个答案。如果它已经知道,它将附加一个新的答案

import numpy as np

known_questions_and_answers = {}
reactions_to_a_new_question = ["Oh, I don't know this!", "Hmm I've never heard of that.", "idk", "owo what's this?", "I'm still learning."]

while True:
    question = input('Ask a question')

    if question in known_questions_and_answers.keys():
        print(np.random.choice(known_questions_and_answers[question])) # Print one answer, randomly chosen in a list of valid answers.
    else:
        print(np.random.choice(reactions_to_a_new_question)) # React to an unknown question.
        known_questions_and_answers[question] = []

    answer = input(f"You tell me, {question}?") # Return the question.
    known_questions_and_answers[question].append(answer) # Append new question-answer pair.

我可能会给你一个有用的
名为tuple
,或
dict
来解决这个问题,但我需要一个更好的例子。请提供一些输入以及这些输入的预期输出。