所以我正在製作一個迷你聊天機器人,如果我問任何問題,但你好,它回答「我很好」 我不是最好的在Python中,所以我可能只是失去了一些東西。爲什麼我的代碼使用不同的elif語句?
代碼:
print("Hello, I am Squeep Bot, my current purpose is to have meaningless conversations with you, please speak to me formally, I can not understand other ways of saying things")
while True:
userInput = input(">>> ")
if userInput in ["hi", "HI", "Hi", "hello", "HELLO", "Hello"]:
print("Hello")
elif ("how", "HOW", "How" in userInput)and("are", "ARE", "Are" in userInput)and("you", "YOU", "You" in userInput):
print ("I'm Ok")
elif ("whats", "WHATS", "Whats", "what's", "WHAT'S", "What's" in userInput)and("favorite", "FAVORITE", "Favorite" in userInput)and("colour", "COLOUR", "Colour" in userInput):
print ("I like Green")
elif ("what", "WHAT", "What" in userInput)and("is", "IS", "Is" in userInput)and("favorite", "FAVORITE", "Favorite" in userInput)and("colour", "COLOUR", "Colour" in userInput):
print ("I like Green")
else:
print("I did not understand what you said")
編譯:
Hello, I am Squeep Bot, my current purpose is to have meaningless conversations with you, please speak to me formally, I can not understand other ways of saying things
>>> hi
Hello
>>> how are you
I'm Ok
>>> whats your favorite colour
I'm Ok
>>> fafasfdf
I'm Ok
>>>
請修正您的縮進。這對Python很重要,上面的版本根本不應該運行。 – Useless