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])輸出結果:

做出簡單版aiml 模組的效果
推薦hahow線上學習python: https://igrape.net/30afN





![Python:如何將folder_path & file_name合併為file_path? fpath = os.path.join (folder , fname) #不需要[ ]包覆folder,fname; fpath1 = “\\”.join( [folder , fname] ) #需要[ ] 包覆folder,fname ; 反過來講,file_path如何拆分為folder_path & file_name? os.path.dirname() ; os.path.basename() ; file_name如何拆分為主檔名與副檔名os.path.splitext() #split(分裂) ext Python:如何將folder_path & file_name合併為file_path? fpath = os.path.join (folder , fname) #不需要[ ]包覆folder,fname; fpath1 = “\\”.join( [folder , fname] ) #需要[ ] 包覆folder,fname ; 反過來講,file_path如何拆分為folder_path & file_name? os.path.dirname() ; os.path.basename() ; file_name如何拆分為主檔名與副檔名os.path.splitext() #split(分裂) ext](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2023/07/20230717184401_87.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python: 如何使用functools.reduce逐步縮減可迭代對象,合併為單個結果? import functools; product = functools.reduce( lambda x, y: x * y, numbers) ; reduce(function, sequence [, initial]) -> value ; map(function, iterable) ; filter(function, iterable) ; map ; filter Python: 如何使用functools.reduce逐步縮減可迭代對象,合併為單個結果? import functools; product = functools.reduce( lambda x, y: x * y, numbers) ; reduce(function, sequence [, initial]) -> value ; map(function, iterable) ; filter(function, iterable) ; map ; filter](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2023/06/20230626093403_49.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


近期留言