質問編集履歴
2
importのコードの追加をしました。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -96,23 +96,91 @@
|
|
|
96
96
|
print("内容:", e)
|
|
97
97
|
|
|
98
98
|
|
|
99
|
-
”
|
|
99
|
+
”import_eto.py”のコード
|
|
100
100
|
|
|
101
101
|
#coding:utf-8
|
|
102
|
-
year str = input('あなたの生まれた年を西暦で入力してください')
|
|
103
|
-
year = int(year star)
|
|
104
|
-
number of eto = (year + 8) % 12
|
|
105
|
-
eto tuple = ("子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥")
|
|
106
|
-
eto name = eto tuple[number of eto]
|
|
107
|
-
print(”あなたの干支は”, eto name, "です")
|
|
108
102
|
|
|
103
|
+
def eto_command(command):
|
|
104
|
+
_ eto, year = command.split()
|
|
105
|
+
_ eto_list = ("子", "丑", "寅", "卯", "辰", "巳", "午",
|
|
106
|
+
_ "未", "申", "酉", "戌", "亥")
|
|
107
|
+
_ eto_number = (int(year) + 8) % 12
|
|
108
|
+
_ eto_name = eto_list[eto_number]
|
|
109
109
|
|
|
110
|
+
_ response = "{}年生まれの干支は「{}」です".format(year, eto_name)
|
|
111
|
+
_ return response
|
|
110
112
|
|
|
113
|
+
"my_random.py"のコード
|
|
111
114
|
|
|
115
|
+
import random
|
|
112
116
|
|
|
117
|
+
def choice_command(command):
|
|
118
|
+
_ data = command.split()
|
|
119
|
+
_ choiced = random.choice(data[1:])
|
|
120
|
+
_ response = "「{}」が選ばれました".format(choiced)
|
|
121
|
+
_ return response
|
|
113
122
|
|
|
123
|
+
def dice_command(command):
|
|
124
|
+
_ num = random.randrange(1, 100)
|
|
125
|
+
_ response = "「{}」の目が出ました".format(num)
|
|
126
|
+
_ return response
|
|
114
127
|
|
|
115
128
|
|
|
129
|
+
"import_hiduke.py"のコード
|
|
130
|
+
|
|
131
|
+
rom datetime import date, datetime
|
|
132
|
+
|
|
133
|
+
def kyou_command():
|
|
134
|
+
_ today = date.today()
|
|
135
|
+
_ response = "今日の日付は{}です".format(today)
|
|
136
|
+
_ return response
|
|
137
|
+
|
|
138
|
+
def ima_command():
|
|
139
|
+
_ now = datetime.now()
|
|
140
|
+
_ response = "現在日時は{}です".format(now)
|
|
141
|
+
_ return response
|
|
142
|
+
|
|
143
|
+
def youbi_command(command):
|
|
144
|
+
_ try:
|
|
145
|
+
_ data = command.split()
|
|
146
|
+
_ year = int(data[1])
|
|
147
|
+
_ month = int(data[2])
|
|
148
|
+
_ day = int(data[3])
|
|
149
|
+
_ one_day = date(year, month, day)
|
|
150
|
+
|
|
151
|
+
_ weekday_str = "月火水木金土日"
|
|
152
|
+
_ weekday = weekday_str[one_day.weekday()]
|
|
153
|
+
|
|
154
|
+
_ response = "{}は、{}曜日です".format(one_day, weekday)
|
|
155
|
+
|
|
156
|
+
_ except IndexError:
|
|
157
|
+
_ response = "3つの値(年月日)を空白で区切って入力して下さい"
|
|
158
|
+
_ except ValueError:
|
|
159
|
+
_ response = "正しい日付を入力して下さい"
|
|
160
|
+
|
|
161
|
+
_ return response
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
"forecast.py"のコード
|
|
165
|
+
|
|
166
|
+
import requests
|
|
167
|
+
|
|
168
|
+
def weather_command():
|
|
169
|
+
_ base_url = "http://weather.livedoor.com/forecast/webservice/json/v1"
|
|
170
|
+
_ city_code = "230010"
|
|
171
|
+
_ url = "{}?city={}".format(base_url, city_code)
|
|
172
|
+
_ r = requests.get(url)
|
|
173
|
+
_ weather_data = r.json()
|
|
174
|
+
_ city = weather_data["location"]["city"]
|
|
175
|
+
_ label = weather_data["forecasts"][0]["dateLabel"]
|
|
176
|
+
_ telop = weather_data["forecasts"][0]["telop"]
|
|
177
|
+
|
|
178
|
+
_ response = "{}の{}の天気は「{}」です".format(city, label, telop)
|
|
179
|
+
_ return response
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
116
184
|
2:エラーコード
|
|
117
185
|
|
|
118
186
|
なんか言え 干支
|
1
インデントを見やすく変更しました
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"干支"、"選ぶ"等のキーワードにも何故か反応しなくなりました。
|
|
5
5
|
どうすれば正常に動作するのか、ご教授お願いします。
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
1:プログラムコード
|
|
8
9
|
|
|
9
10
|
from import_eto import eto_command
|
|
@@ -13,25 +14,25 @@
|
|
|
13
14
|
from forecast import weather_command
|
|
14
15
|
|
|
15
16
|
def len_command(command):
|
|
16
|
-
cmd, text = command.split()
|
|
17
|
+
_ cmd, text = command.split()
|
|
17
|
-
length = len(text)
|
|
18
|
+
_ length = len(text)
|
|
18
|
-
response = "文字列の長さは{}です".format(length)
|
|
19
|
+
_ response = "文字列の長さは{}です".format(length)
|
|
19
|
-
return response
|
|
20
|
+
_ return response
|
|
20
21
|
|
|
21
22
|
def heisei_command(command):
|
|
22
|
-
heisei, year_str = command.split()
|
|
23
|
+
_ heisei, year_str = command.split()
|
|
23
|
-
if year_str.isdigit():
|
|
24
|
+
_ if year_str.isdigit():
|
|
24
|
-
year = int(year_str)
|
|
25
|
+
_ year = int(year_str)
|
|
25
26
|
|
|
26
|
-
if year >= 1989:
|
|
27
|
+
_ if year >= 1989:
|
|
27
|
-
heisei_year = year - 1988
|
|
28
|
+
_ heisei_year = year - 1988
|
|
28
|
-
response = "西暦{}年は、平成{}年です".format(year, heisei_year)
|
|
29
|
+
_ response = "西暦{}年は、平成{}年です".format(year, heisei_year)
|
|
29
|
-
else:
|
|
30
|
+
_ else:
|
|
30
|
-
response = "西暦{}年は、平成ではありません".format(year)
|
|
31
|
+
_ response = "西暦{}年は、平成ではありません".format(year)
|
|
31
32
|
|
|
32
|
-
else:
|
|
33
|
+
_ else:
|
|
33
|
-
response = "数値を指定して下さい"
|
|
34
|
+
_ response = "数値を指定して下さい"
|
|
34
|
-
return response
|
|
35
|
+
_ return response
|
|
35
36
|
|
|
36
37
|
aisatu_file = open("aisatu.txt", encoding="utf-8")
|
|
37
38
|
raw_data = aisatu_file.read()
|
|
@@ -40,54 +41,54 @@
|
|
|
40
41
|
|
|
41
42
|
bot_dict = {}
|
|
42
43
|
for line in lines:
|
|
43
|
-
word_list = line.split(",")
|
|
44
|
+
_ word_list = line.split(",")
|
|
44
|
-
key = word_list[0]
|
|
45
|
+
_ key = word_list[0]
|
|
45
|
-
response = word_list[1]
|
|
46
|
+
_ response = word_list[1]
|
|
46
|
-
bot_dict[key] = response
|
|
47
|
+
_ bot_dict[key] = response
|
|
47
48
|
|
|
48
49
|
while True:
|
|
49
|
-
command = input("なんか言え ")
|
|
50
|
+
_ command = input("なんか言え ")
|
|
50
|
-
response = ""
|
|
51
|
+
_ response = ""
|
|
51
|
-
try:
|
|
52
|
+
_ try:
|
|
52
|
-
for key in bot_dict:
|
|
53
|
+
_ for key in bot_dict:
|
|
53
|
-
if key in command:
|
|
54
|
+
_ if key in command:
|
|
54
|
-
response = bot_dict[key]
|
|
55
|
+
_ response = bot_dict[key]
|
|
55
|
-
break
|
|
56
|
+
_ break
|
|
56
57
|
|
|
57
|
-
if "平成" in command:
|
|
58
|
+
_ if "平成" in command:
|
|
58
|
-
response = heisei_command(command)
|
|
59
|
+
_ response = heisei_command(command)
|
|
59
60
|
|
|
60
|
-
if "長さ" in command:
|
|
61
|
+
_ if "長さ" in command:
|
|
61
|
-
response = len_command(command)
|
|
62
|
+
_ response = len_command(command)
|
|
62
63
|
|
|
63
|
-
if "干支" in command:
|
|
64
|
+
_ if "干支" in command:
|
|
64
|
-
response = eto_command(command)
|
|
65
|
+
_ response = eto_command(command)
|
|
65
66
|
|
|
66
|
-
if "選ぶ" in command:
|
|
67
|
+
_ if "選ぶ" in command:
|
|
67
|
-
response = choice_command(command)
|
|
68
|
+
_ response = choice_command(command)
|
|
68
69
|
|
|
69
|
-
if "サイコロ" in command:
|
|
70
|
+
_ if "サイコロ" in command:
|
|
70
|
-
response = dice_command(command)
|
|
71
|
+
_ response = dice_command(command)
|
|
71
72
|
|
|
72
|
-
if "今日" in command:
|
|
73
|
+
_ if "今日" in command:
|
|
73
|
-
response = kyou_command()
|
|
74
|
+
_ response = kyou_command()
|
|
74
75
|
|
|
75
|
-
if "現在" in command:
|
|
76
|
+
_ if "現在" in command:
|
|
76
|
-
response = ima_command()
|
|
77
|
+
_ response = ima_command()
|
|
77
78
|
|
|
78
|
-
if "曜日" in command:
|
|
79
|
+
_ if "曜日" in command:
|
|
79
|
-
response = youbi_command(command)
|
|
80
|
+
_ response = youbi_command(command)
|
|
80
81
|
|
|
81
|
-
if "天気" in command:
|
|
82
|
+
_ if "天気" in command:
|
|
82
|
-
response = weather_command()
|
|
83
|
+
_ response = weather_command()
|
|
83
|
-
if not response:
|
|
84
|
+
_ if not response:
|
|
84
|
-
response = "日本語喋れや豚野郎"
|
|
85
|
+
_ response = "日本語喋れや豚野郎"
|
|
85
86
|
|
|
86
|
-
print(response)
|
|
87
|
+
_ print(response)
|
|
87
88
|
|
|
88
|
-
if "さようなら" in command:
|
|
89
|
+
_ if "さようなら" in command:
|
|
89
|
-
print("二度と開くなよまじで")
|
|
90
|
+
_ print("二度と開くなよまじで")
|
|
90
|
-
break
|
|
91
|
+
_ break
|
|
91
92
|
|
|
92
93
|
except Exception as e:
|
|
93
94
|
print("予期せぬエラーが発生しました")
|
|
@@ -95,6 +96,23 @@
|
|
|
95
96
|
print("内容:", e)
|
|
96
97
|
|
|
97
98
|
|
|
99
|
+
”干支”のコード
|
|
100
|
+
|
|
101
|
+
#coding:utf-8
|
|
102
|
+
year str = input('あなたの生まれた年を西暦で入力してください')
|
|
103
|
+
year = int(year star)
|
|
104
|
+
number of eto = (year + 8) % 12
|
|
105
|
+
eto tuple = ("子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥")
|
|
106
|
+
eto name = eto tuple[number of eto]
|
|
107
|
+
print(”あなたの干支は”, eto name, "です")
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
98
116
|
2:エラーコード
|
|
99
117
|
|
|
100
118
|
なんか言え 干支
|