Python 如何不断重复输入语句?
我是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
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不是为了取代现有的教程或文档,也不是为你完成研究、设计或编码工作的方式。非常感谢!