教本のを見ながら進めています、初めてのエラーが出てどの様に対処したらいいか困っています。
調べながら自分なりにやってみましたが、なんどやっても同じ結果が返ってきます。
Traceback (most recent call last): File "pybot.py", line 44, in <module> respone = heisei_command(command) File "pybot.py", line 22, in heisei_command return response
どうかご教授いただければと思います。
下記の様にソースコードを書いています。
from pybot_eto import eto_command from pybot_random import choice_command, dice_command from pybot_datetime import today_command, now_command, weekday_command def len_command(command): cmd, text = command.split() length = len(text) response = '文字列ノ長サハ {} 文字デス'.format(length) return response def heisei_command(command): heisei, year_str = command.split() try: year = int(year_str) if year >= 1989: heisei_year = year - 1988 response = '西暦{}年ハ、平成{}年デス'.format(year, heisei_year) else: response = '西暦{}年ハ、平成デハアリマセン'.format(year) except ValueError: resonse = '数値ヲ指定シテクダサイ' return response command_file = open('pybot.txt', encoding='utf-8') raw_data = command_file.read() command_file.close() lines = raw_data.splitlines() bot_dict = {} for line in lines: word_list = line.split(',') key = word_list[0] response = word_list[1] bot_dict[key] = response while True: command = input('pybot> ') response = "" for key in bot_dict: if key in command: response = bot_dict[key] break if '平成' in command: respone = heisei_command(command) if '長さ' in command: response = len_command(command) if '干支' in command: response = eto_command(command) if '選ぶ' in command: response = choice_command(command) if 'さいころ' in command: response = dice_command() if '今日' in command: response = today_command() if '現在' in command: response = now_command() if '曜日' in command: response = weekday_command(command) if not response: response = '何ヲ言ッテルカ、ワカラナイ' print(response) if 'さようなら' in command: break
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/02 06:50
2018/11/02 07:00
2018/11/02 07:32
2018/11/02 07:42
2018/11/02 09:08
2018/11/02 09:10
2018/11/02 11:21