チャットボットを作らなくては意味がありません
完成度はイマイチかもしれませんが
コマンドを打ち込めば言葉が返って来ます
かつてのSiriのようなものです
まずその結果とコードを記します
結果
メッセージを入力; "こんにちは"
"こんにちわ!良い天気ですね!"
メッセージを入力; "おはよう"
"おはようございます!"
メッセージを入力; "げんき"
"私は元気です!"
メッセージを入力; "Python"
"Pythonって最高だよね!"
メッセージを入力; "お出かけですか?"
"スーパーに買い物に出かけます"
メッセージを入力; "趣味は何ですか?"
"読書と空手です"
メッセージを入力; "どのような本を読まれますか?"
"主にPythonのプログラムに関する本です"
メッセージを入力; "スポーツは好きですか?"
"体を動かすのは最高に気分が良いです"
メッセージを入力; "旅行は好きですか?"
"行きたいのですが、時間が取れなくて・・・"
コード
with open('dictionaly.txt', encoding="utf-8") as open_file:
all_data = open_file.read()
all_data = open_file.read()
# 各行のリストを作る
line_list = all_data.splitlines()
line_list = all_data.splitlines()
#読み込んだデータを辞書に追加する
bot_dict = {}
bot_dict = {}
for line in line_list:
orig,trans = line.split(':')
bot_dict[orig] = trans
orig,trans = line.split(':')
bot_dict[orig] = trans
while True:
command = input('メッセージを入力; ')
responce = ""
#辞書のキーが含まれているかチェック
for key in bot_dict:
if key in command:
responce = bot_dict[key]
break
# 空文字の判定
if not responce:
responce = 'あなたとお話がしたいです!なんでも聞いてください!'
print(responce)
if 'さようなら' in command:
break
command = input('メッセージを入力; ')
responce = ""
#辞書のキーが含まれているかチェック
for key in bot_dict:
if key in command:
responce = bot_dict[key]
break
# 空文字の判定
if not responce:
responce = 'あなたとお話がしたいです!なんでも聞いてください!'
print(responce)
if 'さようなら' in command:
break