code:
ask = ["您好嗎", "你是誰"]
ans = ["我很好", "我是聊天機器人"]
while True:
ask_input = input("請輸入你的問題(Q or q to exit):\t")
if ask_input.lower() == "q":
break
if ask_input in ask:
idx = ask.index(ask_input)
print(ans[idx])
輸出結果:
![Python: list.index(元素) 搜尋元素位於list中的那一個index - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2023/10/20231018063752_38.png)
做出簡單版aiml 模組的效果
推薦hahow線上學習python: https://igrape.net/30afN
近期留言