質問編集履歴
1
回答者様からのご指摘から、コードを単純化しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,8 +4,6 @@
|
|
4
4
|
|
5
5
|
```python3.x
|
6
6
|
|
7
|
-
|
8
|
-
|
9
7
|
from pokemon_name import num_set
|
10
8
|
|
11
9
|
import random
|
@@ -44,6 +42,72 @@
|
|
44
42
|
|
45
43
|
|
46
44
|
|
45
|
+
def poke_s():
|
46
|
+
|
47
|
+
global fin
|
48
|
+
|
49
|
+
global d
|
50
|
+
|
51
|
+
num_set.remove(pokemon)#入力したポケモンをリストから消す
|
52
|
+
|
53
|
+
dine = 0#入力にあったポケモンを探す
|
54
|
+
|
55
|
+
draw = 0
|
56
|
+
|
57
|
+
while dine <= 0:
|
58
|
+
|
59
|
+
dime = random.choice(num_set)
|
60
|
+
|
61
|
+
B = list(dime)
|
62
|
+
|
63
|
+
if(dime.startswith(POKEMON[-1]) == True and B[-1] !="ン"):#存在するとき
|
64
|
+
|
65
|
+
print(dime)
|
66
|
+
|
67
|
+
d =B[-1]
|
68
|
+
|
69
|
+
dine += 1
|
70
|
+
|
71
|
+
elif draw ==950:#存在しない (限りなく存在しない)とき
|
72
|
+
|
73
|
+
print("負けました")
|
74
|
+
|
75
|
+
dine += 1# 探索の終了
|
76
|
+
|
77
|
+
fin += 1#ゲームの終了
|
78
|
+
|
79
|
+
else:#未だ探索中のとき
|
80
|
+
|
81
|
+
dine += 0
|
82
|
+
|
83
|
+
draw += 1#もう一度繰り返す
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
print("次は"+ str(d) + "だよ")
|
88
|
+
|
89
|
+
num_set.remove(dime)#パソコンが出力したポケモンをリストから消す
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
def fin_game():
|
94
|
+
|
95
|
+
global fin
|
96
|
+
|
97
|
+
print("そのポケモンいないか、もう使ったよ")
|
98
|
+
|
99
|
+
fin += 1#ゲームの終了
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
47
111
|
while fin <= 0:
|
48
112
|
|
49
113
|
pokemon =input("カタカナで入力してね")
|
@@ -52,195 +116,55 @@
|
|
52
116
|
|
53
117
|
D = POKEMON[0]
|
54
118
|
|
55
|
-
N = POKEMON[
|
56
|
-
|
57
|
-
if N =="ァ":
|
58
|
-
|
59
|
-
POKEMON[
|
60
|
-
|
61
|
-
if pokemon not in num_set:
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
print("負けました")
|
92
|
-
|
93
|
-
dine += 1# 探索の終了
|
94
|
-
|
95
|
-
fin += 1 #ゲームの終了
|
96
|
-
|
97
|
-
else: #未だ探索中のとき
|
98
|
-
|
99
|
-
dine += 0
|
100
|
-
|
101
|
-
draw += 1#もう一度繰り返す
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
print("次は"+ str(d) + "だよ")
|
112
|
-
|
113
|
-
num_set.remove(dime)#パソコンが出力したポケモンをリストから消す
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
elif N =="ィ": #小文字から大文字への変換②
|
120
|
-
|
121
|
-
POKEMON[len(POKEMON)-1] ="イ"
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
if pokemon not in num_set:
|
126
|
-
|
127
|
-
print("そのポケモンいないか、もう使ったよ")
|
128
|
-
|
129
|
-
fin += 1
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
else:
|
134
|
-
|
135
|
-
num_set.remove(pokemon)
|
136
|
-
|
137
|
-
dine = 0
|
138
|
-
|
139
|
-
draw = 0
|
140
|
-
|
141
|
-
while dine <= 0:
|
142
|
-
|
143
|
-
dime = random.choice(num_set)
|
144
|
-
|
145
|
-
B = list(dime)
|
146
|
-
|
147
|
-
if(dime.startswith(POKEMON[len(POKEMON)-1]) == True and B[len(B)-1] !="ン"):
|
148
|
-
|
149
|
-
print(dime)
|
150
|
-
|
151
|
-
dine += 1
|
152
|
-
|
153
|
-
elif draw ==950:
|
154
|
-
|
155
|
-
print("負けました")
|
156
|
-
|
157
|
-
dine += 1
|
158
|
-
|
159
|
-
fin += 1
|
160
|
-
|
161
|
-
else:
|
162
|
-
|
163
|
-
dine += 0
|
164
|
-
|
165
|
-
draw += 1
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
d = B[len(B)-1]
|
170
|
-
|
171
|
-
print("次は"+ str(d) + "だよ")
|
172
|
-
|
173
|
-
num_set.remove(dime)
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
elif N =="ゥ": #小文字から大文字への変換③
|
119
|
+
N = POKEMON[-1]
|
120
|
+
|
121
|
+
if N =="ァ":#小文字から大文字への変換①
|
122
|
+
|
123
|
+
POKEMON[-1] = "ア"
|
124
|
+
|
125
|
+
if pokemon not in num_set:
|
126
|
+
|
127
|
+
fin_game()
|
128
|
+
|
129
|
+
else:
|
130
|
+
|
131
|
+
poke_s()
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
elif N =="ィ":#小文字から大文字への変換②
|
136
|
+
|
137
|
+
POKEMON[-1] ="イ"
|
138
|
+
|
139
|
+
if pokemon not in num_set:
|
140
|
+
|
141
|
+
fin_game()
|
142
|
+
|
143
|
+
else:
|
144
|
+
|
145
|
+
poke_s()
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
elif N =="ゥ":#小文字から大文字への変換③
|
182
154
|
|
183
155
|
POKEMON[len(POKEMON)-1] = "ウ"
|
184
156
|
|
185
|
-
|
186
|
-
|
187
|
-
if pokemon not in num_set:
|
157
|
+
if pokemon not in num_set:
|
188
|
-
|
189
|
-
|
158
|
+
|
190
|
-
|
191
|
-
fin
|
159
|
+
fin_game()
|
192
|
-
|
193
|
-
|
194
|
-
|
160
|
+
|
195
|
-
else:
|
161
|
+
else:
|
196
|
-
|
197
|
-
|
162
|
+
|
198
|
-
|
199
|
-
|
163
|
+
poke_s()
|
200
|
-
|
201
|
-
|
164
|
+
|
202
|
-
|
203
|
-
|
165
|
+
|
204
|
-
|
205
|
-
|
166
|
+
|
206
|
-
|
207
|
-
B = list(dime)
|
208
|
-
|
209
|
-
if(dime.startswith(POKEMON[len(POKEMON)-1]) == True and B[len(B)-1] !="ン"):
|
210
|
-
|
211
|
-
print(dime)
|
212
|
-
|
213
|
-
dine += 1
|
214
|
-
|
215
|
-
elif draw ==950:
|
216
|
-
|
217
|
-
print("負けました")
|
218
|
-
|
219
|
-
dine += 1
|
220
|
-
|
221
|
-
fin += 1
|
222
|
-
|
223
|
-
else:
|
224
|
-
|
225
|
-
dine += 0
|
226
|
-
|
227
|
-
draw += 1
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
d = B[len(B)-1]
|
234
|
-
|
235
|
-
print("次は"+ str(d) + "だよ")
|
236
|
-
|
237
|
-
num_set.remove(dime)
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
elif N == "ェ":
|
167
|
+
elif N == "ェ":#小文字から大文字への変換④
|
244
168
|
|
245
169
|
POKEMON[len(POKEMON)-1] = "エ"
|
246
170
|
|
@@ -248,65 +172,15 @@
|
|
248
172
|
|
249
173
|
if pokemon not in num_set:
|
250
174
|
|
251
|
-
print("そのポケモンいないか、もう使ったよ")
|
252
|
-
|
253
|
-
fin
|
175
|
+
fin_game()
|
254
|
-
|
255
|
-
|
256
|
-
|
176
|
+
|
257
|
-
else:
|
177
|
+
else:
|
258
|
-
|
259
|
-
|
178
|
+
|
260
|
-
|
261
|
-
|
179
|
+
poke_s()
|
262
|
-
|
263
|
-
|
180
|
+
|
264
|
-
|
265
|
-
|
181
|
+
|
266
|
-
|
267
|
-
|
182
|
+
|
268
|
-
|
269
|
-
B = list(dime)
|
270
|
-
|
271
|
-
if(dime.startswith(POKEMON[len(POKEMON)-1]) == True and B[len(B)-1] !="ン"):
|
272
|
-
|
273
|
-
print(dime)
|
274
|
-
|
275
|
-
dine += 1
|
276
|
-
|
277
|
-
elif draw ==950:
|
278
|
-
|
279
|
-
print("負けました")
|
280
|
-
|
281
|
-
dine += 1
|
282
|
-
|
283
|
-
fin += 1
|
284
|
-
|
285
|
-
else:
|
286
|
-
|
287
|
-
dine += 0
|
288
|
-
|
289
|
-
draw += 1
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
d = B[len(B)-1]
|
296
|
-
|
297
|
-
print("次は"+ str(d) + "だよ")
|
298
|
-
|
299
|
-
num_set.remove(dime)
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
elif N == "ォ":
|
183
|
+
elif N == "ォ":#小文字から大文字への変換⑤
|
310
184
|
|
311
185
|
|
312
186
|
|
@@ -316,67 +190,19 @@
|
|
316
190
|
|
317
191
|
if pokemon not in num_set:
|
318
192
|
|
319
|
-
print("そのポケモンいないか、もう使ったよ")
|
320
|
-
|
321
|
-
fin
|
193
|
+
fin_game()
|
322
|
-
|
323
|
-
|
324
|
-
|
194
|
+
|
325
|
-
else:
|
195
|
+
else:
|
326
|
-
|
327
|
-
|
196
|
+
|
328
|
-
|
329
|
-
|
197
|
+
poke_s()
|
330
|
-
|
331
|
-
|
198
|
+
|
332
|
-
|
333
|
-
|
199
|
+
|
334
|
-
|
335
|
-
|
200
|
+
|
336
|
-
|
337
|
-
B = list(dime)
|
338
|
-
|
339
|
-
if(dime.startswith(POKEMON[len(POKEMON)-1]) == True and B[len(B)-1] !="ン"):
|
340
|
-
|
341
|
-
print(dime)
|
342
|
-
|
343
|
-
dine += 1
|
344
|
-
|
345
|
-
elif draw ==950:
|
346
|
-
|
347
|
-
print("負けました")
|
348
|
-
|
349
|
-
dine += 1
|
350
|
-
|
351
|
-
fin += 1
|
352
|
-
|
353
|
-
else:
|
354
|
-
|
355
|
-
dine += 0
|
356
|
-
|
357
|
-
draw += 1
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
d = B[len(B)-1]
|
364
|
-
|
365
|
-
print("次は"+ str(d) + "だよ")
|
366
|
-
|
367
|
-
num_set.remove(dime)
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
elif N =="ン":
|
201
|
+
elif N =="ン":#最後がンの場合の対応
|
376
202
|
|
377
203
|
print("ダメです")
|
378
204
|
|
379
|
-
fin += 1
|
205
|
+
fin += 1#ゲームの終了
|
380
206
|
|
381
207
|
|
382
208
|
|
@@ -384,57 +210,11 @@
|
|
384
210
|
|
385
211
|
if pokemon not in num_set:
|
386
212
|
|
387
|
-
print("そのポケモンいないか、もう使ったよ")
|
388
|
-
|
389
|
-
fin
|
213
|
+
fin_game()
|
390
|
-
|
391
|
-
|
392
|
-
|
214
|
+
|
393
|
-
else:
|
215
|
+
else:
|
394
|
-
|
395
|
-
|
216
|
+
|
396
|
-
|
397
|
-
|
217
|
+
poke_s()
|
398
|
-
|
399
|
-
draw = 0
|
400
|
-
|
401
|
-
while dine <= 0:
|
402
|
-
|
403
|
-
dime = random.choice(num_set)
|
404
|
-
|
405
|
-
B = list(dime)
|
406
|
-
|
407
|
-
if(dime.startswith(POKEMON[len(POKEMON)-1]) == True and B[len(B)-1] !="ン"):
|
408
|
-
|
409
|
-
print(dime)
|
410
|
-
|
411
|
-
dine += 1
|
412
|
-
|
413
|
-
elif draw ==950:
|
414
|
-
|
415
|
-
print("負けました")
|
416
|
-
|
417
|
-
dine += 1
|
418
|
-
|
419
|
-
fin += 1
|
420
|
-
|
421
|
-
else:
|
422
|
-
|
423
|
-
dine += 0
|
424
|
-
|
425
|
-
draw += 1
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
d = B[len(B)-1]
|
434
|
-
|
435
|
-
print("次は"+ str(d) + "だよ")
|
436
|
-
|
437
|
-
num_set.remove(dime)
|
438
218
|
|
439
219
|
|
440
220
|
|
@@ -442,21 +222,15 @@
|
|
442
222
|
|
443
223
|
|
444
224
|
|
445
|
-
quit()
|
225
|
+
quit()#ゲームの終了
|
446
226
|
|
447
227
|
```
|
448
228
|
|
449
229
|
|
450
230
|
|
451
|
-
### 質問
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
231
|
+
いくつかのご指摘から、コードを単純化することに成功しました!
|
456
|
-
|
457
|
-
|
458
|
-
|
232
|
+
|
459
|
-
|
233
|
+
ありがとうございました!
|
460
234
|
|
461
235
|
|
462
236
|
|