質問編集履歴
6
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,107 +22,7 @@
|
|
22
22
|
ビンゴ数は3ですがなぜか20などといった処理した回数がカウントされてしまいます。
|
23
23
|
おそらくビンゴ判定する際の繰り返し処理が原因で
|
24
24
|
|
25
|
-
### 該当のソースコード
|
26
25
|
|
27
|
-
```python
|
28
|
-
import pandas as pd
|
29
|
-
import random
|
30
|
-
import numpy as np
|
31
|
-
|
32
|
-
|
33
|
-
'''ビンゴ表のリスト'''
|
34
|
-
b = random.sample(range(1, 16), k=5)
|
35
|
-
i = random.sample(range(16, 31), k=5)
|
36
|
-
n = random.sample(range(31, 46), k=5)
|
37
|
-
n[2] = 'FREE' #三行目の真ん中をFREEにする。
|
38
|
-
g = random.sample(range(46, 61), k=5)
|
39
|
-
o = random.sample(range(61, 76), k=5)
|
40
|
-
table = [b, i, n, g, o]
|
41
|
-
|
42
|
-
|
43
|
-
'''リストを表にして表示'''
|
44
|
-
df1 = pd.DataFrame(table,
|
45
|
-
index=['b', 'i', 'n', 'g', 'o'],
|
46
|
-
columns=['v', 'w', 'x', 'y', 'z'])
|
47
|
-
|
48
|
-
|
49
|
-
'''ビンゴのボール(1~75までの数字を用意し、シャッフルする)'''
|
50
|
-
num = list(range(1, 76))
|
51
|
-
random.shuffle(num)
|
52
|
-
|
53
|
-
|
54
|
-
'''各カウントアップ'''
|
55
|
-
count_up = 0
|
56
|
-
count_up_bingo = 0
|
57
|
-
count_up_reach = 0
|
58
|
-
|
59
|
-
|
60
|
-
'''各判定処理'''
|
61
|
-
for b_num in num:
|
62
|
-
count_up = count_up + 1
|
63
|
-
if b_num in df1.values:
|
64
|
-
df1 = df1.replace(b_num, '{' + str(b_num) + '}')
|
65
|
-
df = df1.astype(str)
|
66
|
-
print('')
|
67
|
-
print(str(count_up) + '回目!')
|
68
|
-
print('ボールの番号は' + str(b_num) + 'です。当たりなので穴を開けます!')
|
69
|
-
print(df1)
|
70
|
-
print('ーーーーーーーーーーーーーーーーーーーーーーーー')
|
71
|
-
|
72
|
-
'''列判定'''
|
73
|
-
for c in df.columns:
|
74
|
-
count = sum(df[c].str.endswith('}')) + sum(df[c] == 'FREE')
|
75
|
-
if count == 5:
|
76
|
-
count_up_bingo = count_up_bingo + 1
|
77
|
-
elif count == 4:
|
78
|
-
count_up_reach = count_up_reach + 1
|
79
|
-
|
80
|
-
'''行判定'''
|
81
|
-
for r in df.index:
|
82
|
-
count = sum(df.loc[r].str.endswith('}')) + sum(df.loc[r] == 'FREE')
|
83
|
-
if count == 5:
|
84
|
-
count_up_bingo = count_up_bingo + 1
|
85
|
-
elif count == 4:
|
86
|
-
count_up_reach = count_up_reach + 1
|
87
|
-
|
88
|
-
'''斜め判定\'''
|
89
|
-
diagonal_r = list(np.diag(df1))
|
90
|
-
lst = [i for i in diagonal_r if isinstance(i, str)] # 文字列のみ
|
91
|
-
cnt = len(lst)
|
92
|
-
if cnt == 5:
|
93
|
-
count_up_bingo = count_up_bingo + 1
|
94
|
-
elif cnt == 4:
|
95
|
-
count_up_reach = count_up_reach + 1
|
96
|
-
|
97
|
-
'''斜め判定2/'''
|
98
|
-
diagonal_l = list(np.diag(np.fliplr(df1)))
|
99
|
-
lst = [i for i in diagonal_l if isinstance(i, str)] # 文字列のみ
|
100
|
-
cnt2 = len(lst)
|
101
|
-
if cnt2 == 5:
|
102
|
-
count_up_bingo = count_up_bingo + 1
|
103
|
-
elif cnt2 == 4:
|
104
|
-
count_up_reach = count_up_reach + 1
|
105
|
-
|
106
|
-
|
107
|
-
print('ビンゴ数:' + str(count_up_bingo))
|
108
|
-
print('リーチ数:' + str(count_up_reach))
|
109
|
-
|
110
|
-
else:
|
111
|
-
print('')
|
112
|
-
print(str(count_up) + '回目!')
|
113
|
-
print('ボールの番号は' + str(b_num) + 'です。ハズレです!')
|
114
|
-
print(df1)
|
115
|
-
print('ーーーーーーーーーーーーーーーーーーーーーーーー')
|
116
|
-
print('ビンゴ数:' + str(count_up_bingo))
|
117
|
-
print('リーチ数:' + str(count_up_reach))
|
118
|
-
|
119
|
-
if count_up == 75:
|
120
|
-
print('')
|
121
|
-
print('_人人人人人人人人人人人_')
|
122
|
-
print('> ビンゴゲーム終了!! <')
|
123
|
-
print(' ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄')
|
124
|
-
```
|
125
|
-
|
126
26
|
### 試したこと
|
127
27
|
|
128
28
|
ifの中でrange()を使って回数制限をしたり、
|
5
インデント修正しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -103,9 +103,10 @@
|
|
103
103
|
elif cnt2 == 4:
|
104
104
|
count_up_reach = count_up_reach + 1
|
105
105
|
|
106
|
-
print('ビンゴ数:' + str(count_up_bingo))
|
107
|
-
print('リーチ数:' + str(count_up_reach))
|
108
106
|
|
107
|
+
print('ビンゴ数:' + str(count_up_bingo))
|
108
|
+
print('リーチ数:' + str(count_up_reach))
|
109
|
+
|
109
110
|
else:
|
110
111
|
print('')
|
111
112
|
print(str(count_up) + '回目!')
|
4
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -103,8 +103,8 @@
|
|
103
103
|
elif cnt2 == 4:
|
104
104
|
count_up_reach = count_up_reach + 1
|
105
105
|
|
106
|
-
|
106
|
+
print('ビンゴ数:' + str(count_up_bingo))
|
107
|
-
|
107
|
+
print('リーチ数:' + str(count_up_reach))
|
108
108
|
|
109
109
|
else:
|
110
110
|
print('')
|
3
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -25,36 +25,101 @@
|
|
25
25
|
### 該当のソースコード
|
26
26
|
|
27
27
|
```python
|
28
|
+
import pandas as pd
|
29
|
+
import random
|
30
|
+
import numpy as np
|
28
31
|
|
29
|
-
bingo_count = 0
|
30
32
|
|
33
|
+
'''ビンゴ表のリスト'''
|
34
|
+
b = random.sample(range(1, 16), k=5)
|
31
|
-
|
35
|
+
i = random.sample(range(16, 31), k=5)
|
36
|
+
n = random.sample(range(31, 46), k=5)
|
37
|
+
n[2] = 'FREE' #三行目の真ん中をFREEにする。
|
38
|
+
g = random.sample(range(46, 61), k=5)
|
39
|
+
o = random.sample(range(61, 76), k=5)
|
40
|
+
table = [b, i, n, g, o]
|
41
|
+
|
42
|
+
|
43
|
+
'''リストを表にして表示'''
|
44
|
+
df1 = pd.DataFrame(table,
|
45
|
+
index=['b', 'i', 'n', 'g', 'o'],
|
46
|
+
columns=['v', 'w', 'x', 'y', 'z'])
|
47
|
+
|
48
|
+
|
49
|
+
'''ビンゴのボール(1~75までの数字を用意し、シャッフルする)'''
|
50
|
+
num = list(range(1, 76))
|
51
|
+
random.shuffle(num)
|
52
|
+
|
53
|
+
|
54
|
+
'''各カウントアップ'''
|
55
|
+
count_up = 0
|
56
|
+
count_up_bingo = 0
|
57
|
+
count_up_reach = 0
|
58
|
+
|
59
|
+
|
32
|
-
|
60
|
+
'''各判定処理'''
|
61
|
+
for b_num in num:
|
62
|
+
count_up = count_up + 1
|
33
|
-
if
|
63
|
+
if b_num in df1.values:
|
34
|
-
df1 = df1.replace(
|
64
|
+
df1 = df1.replace(b_num, '{' + str(b_num) + '}')
|
35
65
|
df = df1.astype(str)
|
66
|
+
print('')
|
36
|
-
''
|
67
|
+
print(str(count_up) + '回目!')
|
68
|
+
print('ボールの番号は' + str(b_num) + 'です。当たりなので穴を開けます!')
|
69
|
+
print(df1)
|
70
|
+
print('ーーーーーーーーーーーーーーーーーーーーーーーー')
|
37
71
|
|
38
|
-
|
39
|
-
'''
|
72
|
+
'''列判定'''
|
40
73
|
for c in df.columns:
|
41
|
-
count = sum(df[c].str.endswith('}')) + sum(df[c] == '
|
74
|
+
count = sum(df[c].str.endswith('}')) + sum(df[c] == 'FREE')
|
42
|
-
if count == 5:
|
75
|
+
if count == 5:
|
43
|
-
|
76
|
+
count_up_bingo = count_up_bingo + 1
|
44
|
-
print(bingo_count)
|
45
77
|
elif count == 4:
|
46
|
-
|
78
|
+
count_up_reach = count_up_reach + 1
|
47
|
-
|
48
|
-
#[out]
|
49
|
-
…
|
50
|
-
…
|
51
|
-
…
|
52
|
-
16
|
53
|
-
17
|
54
|
-
18
|
55
|
-
19
|
56
|
-
20
|
57
79
|
|
80
|
+
'''行判定'''
|
81
|
+
for r in df.index:
|
82
|
+
count = sum(df.loc[r].str.endswith('}')) + sum(df.loc[r] == 'FREE')
|
83
|
+
if count == 5:
|
84
|
+
count_up_bingo = count_up_bingo + 1
|
85
|
+
elif count == 4:
|
86
|
+
count_up_reach = count_up_reach + 1
|
87
|
+
|
88
|
+
'''斜め判定\'''
|
89
|
+
diagonal_r = list(np.diag(df1))
|
90
|
+
lst = [i for i in diagonal_r if isinstance(i, str)] # 文字列のみ
|
91
|
+
cnt = len(lst)
|
92
|
+
if cnt == 5:
|
93
|
+
count_up_bingo = count_up_bingo + 1
|
94
|
+
elif cnt == 4:
|
95
|
+
count_up_reach = count_up_reach + 1
|
96
|
+
|
97
|
+
'''斜め判定2/'''
|
98
|
+
diagonal_l = list(np.diag(np.fliplr(df1)))
|
99
|
+
lst = [i for i in diagonal_l if isinstance(i, str)] # 文字列のみ
|
100
|
+
cnt2 = len(lst)
|
101
|
+
if cnt2 == 5:
|
102
|
+
count_up_bingo = count_up_bingo + 1
|
103
|
+
elif cnt2 == 4:
|
104
|
+
count_up_reach = count_up_reach + 1
|
105
|
+
|
106
|
+
print('ビンゴ数:' + str(count_up_bingo))
|
107
|
+
print('リーチ数:' + str(count_up_reach))
|
108
|
+
|
109
|
+
else:
|
110
|
+
print('')
|
111
|
+
print(str(count_up) + '回目!')
|
112
|
+
print('ボールの番号は' + str(b_num) + 'です。ハズレです!')
|
113
|
+
print(df1)
|
114
|
+
print('ーーーーーーーーーーーーーーーーーーーーーーーー')
|
115
|
+
print('ビンゴ数:' + str(count_up_bingo))
|
116
|
+
print('リーチ数:' + str(count_up_reach))
|
117
|
+
|
118
|
+
if count_up == 75:
|
119
|
+
print('')
|
120
|
+
print('_人人人人人人人人人人人_')
|
121
|
+
print('> ビンゴゲーム終了!! <')
|
122
|
+
print(' ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄')
|
58
123
|
```
|
59
124
|
|
60
125
|
### 試したこと
|
2
処理の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -29,7 +29,14 @@
|
|
29
29
|
bingo_count = 0
|
30
30
|
|
31
31
|
for b_num in num: #たまの数だけ繰り返し処理をする。(省略)
|
32
|
+
'''省略'''
|
33
|
+
if num in df1.values: #たまの数字が表にあった時に書き換える処理
|
34
|
+
df1 = df1.replace(num, '')
|
35
|
+
df = df1.astype(str)
|
36
|
+
'''省略'''
|
37
|
+
|
38
|
+
|
32
|
-
|
39
|
+
'''縦の判定'''
|
33
40
|
for c in df.columns:
|
34
41
|
count = sum(df[c].str.endswith('}')) + sum(df[c] == 'カラ') #ココで穴の空いた数字とカラをカウントしてその数が5であればカウントする。
|
35
42
|
if count == 5:
|
1
誤表記の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -33,8 +33,8 @@
|
|
33
33
|
for c in df.columns:
|
34
34
|
count = sum(df[c].str.endswith('}')) + sum(df[c] == 'カラ') #ココで穴の空いた数字とカラをカウントしてその数が5であればカウントする。
|
35
35
|
if count == 5:
|
36
|
-
|
36
|
+
bingo_count = bingo_count + 1
|
37
|
-
print(
|
37
|
+
print(bingo_count)
|
38
38
|
elif count == 4:
|
39
39
|
count = count + 1
|
40
40
|
|