在这种情况下如何使用“while”?

时间:2016-10-29 12:38:15

标签: python

我目前正在制作一个'猜猜动物'游戏,用户将在其中输入一个问题,它将生成一个答案。但是,我仍然坚持尝试在循环时做出“这个问题不被识别”。

while questionone.find("bird") or questionone.find("mammal") not in questionone:
    print("This question isn't recognised.")
    print("Ask another question or check for typos.")
    print("This will not count towards your 5 questions.")
    questionone = input("What is your question? ")
    questionone = questionone.lower()

我该如何解决这个问题? 任何回复都将不胜感激。

1 个答案:

答案 0 :(得分:2)

循环条件是

while 'bird' not in questionone and 'mammal' not in questionone:

要将此扩展为您要检查的一组字词,可以使用

while not any(word in questionone for word in {'bird', 'mammal', 'etc'}:
相关问题