質問編集履歴
4
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,7 +28,23 @@
|
|
28
28
|
|
29
29
|
といったような構成で現在、4をうまく実装できずにでつまずいています。
|
30
30
|
|
31
|
+
[[講師1, 優先度高]
|
32
|
+
|
33
|
+
[講師4, 優先度中]
|
34
|
+
|
35
|
+
[講師2, 優先度中]
|
36
|
+
|
37
|
+
[講師3, 優先度低]
|
38
|
+
|
39
|
+
]
|
40
|
+
|
41
|
+
に生徒を登録する際に
|
42
|
+
|
43
|
+
{講師1:[生徒1,生徒2],講師4:[],講師2:[],講師3:[]}
|
44
|
+
|
31
|
-
|
45
|
+
まではうまくいくが、生徒3以降が講師4に登録されない点でつまずいています。
|
46
|
+
|
47
|
+
うまくいく方法があればご教授ください。
|
32
48
|
|
33
49
|
|
34
50
|
|
3
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -335,3 +335,143 @@
|
|
335
335
|
"高校倫政" INTEGER
|
336
336
|
|
337
337
|
)
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
```csv
|
342
|
+
|
343
|
+
name,適正I,適正II,算国,中学数学,中学英語,中学国語,中学理科,中学社会,高校数学,高校物理,高校化学,高校生物,高校英語,高校国語,高校日本史,高校世界史,高校地理,高校倫政
|
344
|
+
|
345
|
+
櫻井翔,0,0,0,5,5,5,2,4,0,0,0,0,3,3,4,4,4,0
|
346
|
+
|
347
|
+
相葉雅紀,3,3,3,5,5,5,3,0,5,4,5,5,0,0,0,0,0,0
|
348
|
+
|
349
|
+
二宮和也,4,0,0,5,5,5,0,0,5,5,5,0,5,0,0,0,0,0
|
350
|
+
|
351
|
+
松本潤,3,3,4,5,5,5,5,5,4,5,5,4,5,3,0,0,0,0
|
352
|
+
|
353
|
+
大野智,2,2,1,4,4,5,5,3,2,0,2,1,2,0,4,3,4,3
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
```
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
CREATE TABLE "teacher_schedule" (
|
362
|
+
|
363
|
+
"name" TEXT,
|
364
|
+
|
365
|
+
"月曜1" INTEGER,
|
366
|
+
|
367
|
+
"月曜2" INTEGER,
|
368
|
+
|
369
|
+
"月曜3" INTEGER,
|
370
|
+
|
371
|
+
"月曜4" INTEGER,
|
372
|
+
|
373
|
+
"月曜5" INTEGER,
|
374
|
+
|
375
|
+
"月曜7" INTEGER,
|
376
|
+
|
377
|
+
"火曜1" INTEGER,
|
378
|
+
|
379
|
+
"火曜2" INTEGER,
|
380
|
+
|
381
|
+
"火曜3" INTEGER,
|
382
|
+
|
383
|
+
"火曜4" INTEGER,
|
384
|
+
|
385
|
+
"火曜5" INTEGER,
|
386
|
+
|
387
|
+
"火曜6" INTEGER,
|
388
|
+
|
389
|
+
"火曜7" INTEGER,
|
390
|
+
|
391
|
+
"水曜1" INTEGER,
|
392
|
+
|
393
|
+
"水曜2" INTEGER,
|
394
|
+
|
395
|
+
"水曜3" INTEGER,
|
396
|
+
|
397
|
+
"水曜4" INTEGER,
|
398
|
+
|
399
|
+
"水曜5" INTEGER,
|
400
|
+
|
401
|
+
"水曜6" INTEGER,
|
402
|
+
|
403
|
+
"水曜7" INTEGER,
|
404
|
+
|
405
|
+
"木曜1" INTEGER,
|
406
|
+
|
407
|
+
"木曜2" INTEGER,
|
408
|
+
|
409
|
+
"木曜3" INTEGER,
|
410
|
+
|
411
|
+
"木曜4" INTEGER,
|
412
|
+
|
413
|
+
"木曜5" INTEGER,
|
414
|
+
|
415
|
+
"木曜6" INTEGER,
|
416
|
+
|
417
|
+
"木曜7" INTEGER,
|
418
|
+
|
419
|
+
"金曜1" INTEGER,
|
420
|
+
|
421
|
+
"金曜2" INTEGER,
|
422
|
+
|
423
|
+
"金曜3" INTEGER,
|
424
|
+
|
425
|
+
"金曜4" INTEGER,
|
426
|
+
|
427
|
+
"金曜5" INTEGER,
|
428
|
+
|
429
|
+
"金曜6" INTEGER,
|
430
|
+
|
431
|
+
"金曜7" INTEGER,
|
432
|
+
|
433
|
+
"土曜1" INTEGER,
|
434
|
+
|
435
|
+
"土曜2" INTEGER,
|
436
|
+
|
437
|
+
"土曜3" INTEGER,
|
438
|
+
|
439
|
+
"土曜4" INTEGER,
|
440
|
+
|
441
|
+
"土曜5" INTEGER,
|
442
|
+
|
443
|
+
"土曜6" INTEGER,
|
444
|
+
|
445
|
+
"土曜7" INTEGER,
|
446
|
+
|
447
|
+
"日曜1" INTEGER,
|
448
|
+
|
449
|
+
"日曜2" INTEGER,
|
450
|
+
|
451
|
+
"日曜3" INTEGER,
|
452
|
+
|
453
|
+
"日曜4" INTEGER,
|
454
|
+
|
455
|
+
"日曜5" INTEGER,
|
456
|
+
|
457
|
+
"日曜6" INTEGER,
|
458
|
+
|
459
|
+
"日曜7" INTEGER
|
460
|
+
|
461
|
+
)
|
462
|
+
|
463
|
+
```csv
|
464
|
+
|
465
|
+
name,月曜1,月曜2,月曜3,月曜4,月曜5,月曜7,火曜1,火曜2,火曜3,火曜4,火曜5,火曜6,火曜7,水曜1,水曜2,水曜3,水曜4,水曜5,水曜6,水曜7,木曜1,木曜2,木曜3,木曜4,木曜5,木曜6,木曜7,金曜1,金曜2,金曜3,金曜4,金曜5,金曜6,金曜7,土曜1,土曜2,土曜3,土曜4,土曜5,土曜6,土曜7,日曜1,日曜2,日曜3,日曜4,日曜5,日曜6,日曜7
|
466
|
+
|
467
|
+
櫻井翔,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1
|
468
|
+
|
469
|
+
相葉雅紀,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1
|
470
|
+
|
471
|
+
二宮和也,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
472
|
+
|
473
|
+
松本潤,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,1,1,0,0,0,0,0,1,1,1,1,1,1,1
|
474
|
+
|
475
|
+
大野智,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1
|
476
|
+
|
477
|
+
```
|
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,15 +30,139 @@
|
|
30
30
|
|
31
31
|
具体的には次のような書き方でネストの仕方などを変えながら考えていますがうまくいきません。
|
32
32
|
|
33
|
+
|
34
|
+
|
33
35
|
```python
|
34
36
|
|
37
|
+
#coding: utf-8
|
38
|
+
|
39
|
+
import sqlite3
|
40
|
+
|
41
|
+
import pprint
|
42
|
+
|
43
|
+
import sys
|
44
|
+
|
45
|
+
conn = sqlite3.connect("koma.db")
|
46
|
+
|
47
|
+
c = conn.cursor()
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
# コマを組みたい生徒を選ぶ
|
52
|
+
|
53
|
+
def student_choice(c, date, time):
|
54
|
+
|
55
|
+
c.execute("select name from student where schedule like '%{}{}%' ".format(date, time,))
|
56
|
+
|
57
|
+
print("---------------")
|
58
|
+
|
59
|
+
print("生徒を表示")
|
60
|
+
|
61
|
+
for row in c:
|
62
|
+
|
63
|
+
print(list(row))
|
64
|
+
|
65
|
+
student_all.append(list(row))
|
66
|
+
|
67
|
+
print("登録したい生徒を入力: ", end = "")
|
68
|
+
|
69
|
+
global student_name
|
70
|
+
|
71
|
+
student_name = input()
|
72
|
+
|
73
|
+
c.execute("select subject from student where name like ?; ", (student_name,))
|
74
|
+
|
75
|
+
for row in c:
|
76
|
+
|
77
|
+
print(list(row))
|
78
|
+
|
79
|
+
print("登録したい科目を入力: ", end = "")
|
80
|
+
|
81
|
+
global subject
|
82
|
+
|
83
|
+
subject = input()
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
# 選んだ生徒を担当できる講師を探す
|
88
|
+
|
89
|
+
def schedule(c, subject, date, time):
|
90
|
+
|
91
|
+
print("---------------")
|
92
|
+
|
93
|
+
print("担当可能講師を表示")
|
94
|
+
|
95
|
+
c.execute("select teacher.name, {} from teacher, teacher_schedule where teacher.name = teacher_schedule.name and {} > 0 and {}{} = 0"
|
96
|
+
|
97
|
+
.format(subject, subject, date, time,))
|
98
|
+
|
99
|
+
global priority
|
100
|
+
|
101
|
+
priority = []
|
102
|
+
|
103
|
+
for row in c:
|
104
|
+
|
105
|
+
#print(list(row))
|
106
|
+
|
107
|
+
priority.append(list(row))
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
# 探した講師から優先順位を考慮して計算
|
112
|
+
|
113
|
+
def priority_calculation(priority, relation, all_relation):
|
114
|
+
|
115
|
+
sum = 0
|
116
|
+
|
35
117
|
i = 0
|
36
118
|
|
119
|
+
while i < len(priority):
|
120
|
+
|
121
|
+
sum += priority[i][1]
|
122
|
+
|
123
|
+
i += 1
|
124
|
+
|
125
|
+
ave = sum / len(priority)
|
126
|
+
|
127
|
+
j = 0
|
128
|
+
|
129
|
+
while j < len(priority):
|
130
|
+
|
131
|
+
f = float(priority[j][1]/ave) - float(len(priority)/len(student_all))
|
132
|
+
|
133
|
+
priority[j].append(f)
|
134
|
+
|
135
|
+
j += 1
|
136
|
+
|
137
|
+
#print(priority)
|
138
|
+
|
139
|
+
global priority_sort
|
140
|
+
|
141
|
+
priority_sort = sorted(priority, key = lambda x: x[2], reverse = True)
|
142
|
+
|
143
|
+
pprint.pprint(priority_sort, width = 40)
|
144
|
+
|
145
|
+
for row in priority_sort:
|
146
|
+
|
147
|
+
relation.setdefault(row[0], [])
|
148
|
+
|
149
|
+
#print(relation)
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
def entry(priority_sort, relation, student_name):
|
156
|
+
|
157
|
+
i = 0
|
158
|
+
|
37
159
|
while i < len(priority_sort):
|
38
160
|
|
39
161
|
for k, v in relation.items():
|
40
162
|
|
163
|
+
#print(k)
|
164
|
+
|
41
|
-
if s
|
165
|
+
if priority_sort[i][0] == k:
|
42
166
|
|
43
167
|
if len(v) < 2:
|
44
168
|
|
@@ -48,46 +172,166 @@
|
|
48
172
|
|
49
173
|
break
|
50
174
|
|
175
|
+
print(relation)
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
print("曜日を選択")
|
182
|
+
|
183
|
+
print("月曜|火曜|水曜|木曜|金曜|土曜|日曜")
|
184
|
+
|
185
|
+
date = input()
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
print("---------------")
|
190
|
+
|
191
|
+
print("時間を番号で選択")
|
192
|
+
|
193
|
+
print("1. 10:40 ~ 12:00")
|
194
|
+
|
195
|
+
print("2. 12:10 ~ 13:30")
|
196
|
+
|
197
|
+
print("3. 14:00 ~ 15:20")
|
198
|
+
|
199
|
+
print("4. 15:30 ~ 16:50")
|
200
|
+
|
201
|
+
print("5. 17:20 ~ 18:40")
|
202
|
+
|
203
|
+
print("6. 18:50 ~ 20:10")
|
204
|
+
|
205
|
+
print("7. 20:20 ~ 21:40")
|
206
|
+
|
207
|
+
time = str(input())
|
208
|
+
|
209
|
+
student_all = []
|
210
|
+
|
211
|
+
#priority = []
|
212
|
+
|
213
|
+
all_relation = []
|
214
|
+
|
215
|
+
relation = {}
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
while True:
|
220
|
+
|
221
|
+
student_choice(c, date, time)
|
222
|
+
|
223
|
+
schedule(c, subject, date, time)
|
224
|
+
|
225
|
+
priority_calculation(priority, relation, all_relation)
|
226
|
+
|
227
|
+
entry(priority_sort, relation, student_name)
|
228
|
+
|
229
|
+
print("1: 同じ時間帯で登録する.")
|
230
|
+
|
231
|
+
print("2: この時間の登録を終了する.")
|
232
|
+
|
233
|
+
a = input()
|
234
|
+
|
235
|
+
if a == "1":
|
236
|
+
|
237
|
+
True
|
238
|
+
|
239
|
+
elif a == "2":
|
240
|
+
|
241
|
+
print("終了します.")
|
242
|
+
|
243
|
+
break
|
244
|
+
|
245
|
+
|
246
|
+
|
51
247
|
```
|
52
248
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
92
|
-
|
93
|
-
|
249
|
+
水曜の7の時間に多くの生徒を登録してあるので、水曜->7で実行してください
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
以下koma.db の 内容です
|
256
|
+
|
257
|
+
CREATE TABLE "student" (
|
258
|
+
|
259
|
+
"name" TEXT,
|
260
|
+
|
261
|
+
"year" TEXT,
|
262
|
+
|
263
|
+
"subject" TEXT,
|
264
|
+
|
265
|
+
"schedule" TEXT
|
266
|
+
|
267
|
+
)
|
268
|
+
|
269
|
+
```csv
|
270
|
+
|
271
|
+
name,year,subject,schedule
|
272
|
+
|
273
|
+
竹内涼真,h3,"高校数学,高校化学","火曜7,水曜7"
|
274
|
+
|
275
|
+
小栗旬,j3,"中学数学,中学理科,中学英語,中学国語,中学社会","木曜6,木曜7,金曜6,金曜7"
|
276
|
+
|
277
|
+
新垣結衣,h2,"高校数学,高校英語,高校世界史","土曜6,土曜7"
|
278
|
+
|
279
|
+
松坂桃李,j1,"中学数学,中学数学","火曜5,火曜6"
|
280
|
+
|
281
|
+
本田翼,j3,"中学数学,中学英語","水曜7,木曜5,木曜6"
|
282
|
+
|
283
|
+
戸田恵梨香,h1,"高校数学,高校英語,高校物理","水曜6,水曜7"
|
284
|
+
|
285
|
+
宇垣美里,j2,"中学数学,中学英語","火曜7,水曜7,木曜7"
|
286
|
+
|
287
|
+
福士蒼汰,j2,"中学数学,中学英語,中学理科","水曜6,水曜7,土曜6"
|
288
|
+
|
289
|
+
山崎賢人,h1,高校数学,水曜7
|
290
|
+
|
291
|
+
長澤まさみ,h1,"高校数学,高校英語","水曜7,金曜6,金曜7"
|
292
|
+
|
293
|
+
石原さとみ,h1,"高校数学,高校英語",水曜7
|
294
|
+
|
295
|
+
```
|
296
|
+
|
297
|
+
CREATE TABLE "teacher" (
|
298
|
+
|
299
|
+
"name" TEXT,
|
300
|
+
|
301
|
+
"適正I" INTEGER,
|
302
|
+
|
303
|
+
"適正II" INTEGER,
|
304
|
+
|
305
|
+
"算国" INTEGER,
|
306
|
+
|
307
|
+
"中学数学" INTEGER,
|
308
|
+
|
309
|
+
"中学英語" INTEGER,
|
310
|
+
|
311
|
+
"中学国語" INTEGER,
|
312
|
+
|
313
|
+
"中学理科" INTEGER,
|
314
|
+
|
315
|
+
"中学社会" INTEGER,
|
316
|
+
|
317
|
+
"高校数学" INTEGER,
|
318
|
+
|
319
|
+
"高校物理" INTEGER,
|
320
|
+
|
321
|
+
"高校化学" INTEGER,
|
322
|
+
|
323
|
+
"高校生物" INTEGER,
|
324
|
+
|
325
|
+
"高校英語" INTEGER,
|
326
|
+
|
327
|
+
"高校国語" INTEGER,
|
328
|
+
|
329
|
+
"高校日本史" INTEGER,
|
330
|
+
|
331
|
+
"高校世界史" INTEGER,
|
332
|
+
|
333
|
+
"高校地理" INTEGER,
|
334
|
+
|
335
|
+
"高校倫政" INTEGER
|
336
|
+
|
337
|
+
)
|
1
タイトルの変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
python
|
1
|
+
python dictのkeyの取り出し
|
test
CHANGED
@@ -90,6 +90,4 @@
|
|
90
90
|
|
91
91
|
|
92
92
|
|
93
|
-
|
94
|
-
|
95
93
|
何かネストの方法やbreakの位置などうまくいく方法や、全く別の方法でもうまいやり方がありましたらご教授いただけると嬉しいです。
|