Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何不断重复输入语句?_Python_Input - Fatal编程技术网

Python 如何不断重复输入语句?

Python 如何不断重复输入语句?,python,input,Python,Input,我是Python新手,一直在尝试开发聊天机器人。这是密码 print("Hi! I am AUGbot") x = input() if x == "hi": print("Hello!") elif x == "hello": print("Hi!") elif x == "how are you": print("I am fine! Ho

我是Python新手,一直在尝试开发聊天机器人。这是密码

print("Hi! I am AUGbot")
x = input()
if x == "hi":
    print("Hello!")
elif x == "hello":
    print("Hi!")
elif x == "how are you":
    print("I am fine! How are you?")
elif x == "i am fine":
    print("Nice!")
elif x == "i am not fine":
    print("Oh, Sorry to know that")
else:
    print("I am not sure I understand")
代码执行后,它将结束。即使在用户给出输入后,我如何保持输入语句运行?非常感谢您的帮助。

以下是完整的代码:

print("Hi! I am Jarvis.Let me know, how i can assist you?")
while True:
    user_input = input("Leave Your Message...")
    if user_input == "hi":
        print("Hello")
    elif user_input == "hello":
        print("Hi")
    elif user_input == "how are you":
        print("I am fine! How are you?")
    elif user_input == "i am fine":
        print("Nice!")
    elif user_input == "i am not fine":
        print("Oh, Sorry to know that")
    elif user_input == "exit":
        print("Thank you!")
        break
    else:
        print("I am not sure I understand!Type Again")

你知道吗?你试过使用它们吗?谢谢你的回复。我对Python有点陌生,所以我不理解while循环的概念。你能帮我吗?Stack Overflow不是为了取代现有的教程或文档,也不是为你完成研究、设计或编码工作的方式。非常感谢!