If statement 如何让我的python3代码做很多事情;如果输入“;立即行动

If statement 如何让我的python3代码做很多事情;如果输入“;立即行动,if-statement,python-3.x,input,artificial-intelligence,If Statement,Python 3.x,Input,Artificial Intelligence,我试着做一个人工智能只是想看看我能不能,我不能。但我希望它至少能起作用。 这是我的密码: 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

我试着做一个人工智能只是想看看我能不能,我不能。但我希望它至少能起作用。 这是我的密码:

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.")

如果你运行它,你会发现它与人工智能不一样。

你可以使用
while
循环,这样你的代码就可以继续执行,只要用户没有像这样输入“再见”。我还输入了一个
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!")

如果这不是你想要的,或者有什么你不明白的,请告诉我

您现在每次都在请求输入。相反,尝试执行一次
input(“:”
),并将结果存储在变量中,然后针对该变量编写
if
s。还有,
如果为True:
的意义是什么?对不起,我的代码中有输入错误,我实际上是True