我怎样才能使我的 python3 代码同时执行许多 "if input" 操作

How can i make my python3 code do many "if input" operations at once

我试过做一个人工智能只是为了看看我能不能,我不能。但我希望它至少能工作。 这是我的代码:

while True:
   if input(":") == "hello":
       print("Hello.")
   if input(":") == "good bye":
       print("Bye!")
   if input(":") == "how are you":
       print("Good, i don't feel much. You know, I'm an AI.")

如果你 运行 你会发现它不是 AI 会做的事情。

您可以使用 while 循环,这样只要用户不输入 "good bye",您的代码就会继续执行,就像这样。我还输入了一个 else 语句,以防用户输入您的 AI 无法处理的内容。

user_input = ""
while user_input != "good bye":
   user_input = input(":")
   if user_input == "hello":
       print("Hello.")
   elif user_input == "how are you":
       print("Good, i don't feel much. You know, I'm an AI.")
   else :
      print("Say something I understand")
print("Bye!")

如果这不是您想要的或者您不明白的地方,请告诉我。