質問編集履歴

6

書式の改善

2021/01/12 04:13

投稿

nre
nre

スコア35

test CHANGED
File without changes
test CHANGED
@@ -46,206 +46,6 @@
46
46
 
47
47
 
48
48
 
49
- ### 該当のソースコード
50
-
51
-
52
-
53
- ```python
54
-
55
- import pandas as pd
56
-
57
- import random
58
-
59
- import numpy as np
60
-
61
-
62
-
63
-
64
-
65
- '''ビンゴ表のリスト'''
66
-
67
- b = random.sample(range(1, 16), k=5)
68
-
69
- i = random.sample(range(16, 31), k=5)
70
-
71
- n = random.sample(range(31, 46), k=5)
72
-
73
- n[2] = 'FREE' #三行目の真ん中をFREEにする。
74
-
75
- g = random.sample(range(46, 61), k=5)
76
-
77
- o = random.sample(range(61, 76), k=5)
78
-
79
- table = [b, i, n, g, o]
80
-
81
-
82
-
83
-
84
-
85
- '''リストを表にして表示'''
86
-
87
- df1 = pd.DataFrame(table,
88
-
89
- index=['b', 'i', 'n', 'g', 'o'],
90
-
91
- columns=['v', 'w', 'x', 'y', 'z'])
92
-
93
-
94
-
95
-
96
-
97
- '''ビンゴのボール(1~75までの数字を用意し、シャッフルする)'''
98
-
99
- num = list(range(1, 76))
100
-
101
- random.shuffle(num)
102
-
103
-
104
-
105
-
106
-
107
- '''各カウントアップ'''
108
-
109
- count_up = 0
110
-
111
- count_up_bingo = 0
112
-
113
- count_up_reach = 0
114
-
115
-
116
-
117
-
118
-
119
- '''各判定処理'''
120
-
121
- for b_num in num:
122
-
123
- count_up = count_up + 1
124
-
125
- if b_num in df1.values:
126
-
127
- df1 = df1.replace(b_num, '{' + str(b_num) + '}')
128
-
129
- df = df1.astype(str)
130
-
131
- print('')
132
-
133
- print(str(count_up) + '回目!')
134
-
135
- print('ボールの番号は' + str(b_num) + 'です。当たりなので穴を開けます!')
136
-
137
- print(df1)
138
-
139
- print('ーーーーーーーーーーーーーーーーーーーーーーーー')
140
-
141
-
142
-
143
- '''列判定'''
144
-
145
- for c in df.columns:
146
-
147
- count = sum(df[c].str.endswith('}')) + sum(df[c] == 'FREE')
148
-
149
- if count == 5:
150
-
151
- count_up_bingo = count_up_bingo + 1
152
-
153
- elif count == 4:
154
-
155
- count_up_reach = count_up_reach + 1
156
-
157
-
158
-
159
- '''行判定'''
160
-
161
- for r in df.index:
162
-
163
- count = sum(df.loc[r].str.endswith('}')) + sum(df.loc[r] == 'FREE')
164
-
165
- if count == 5:
166
-
167
- count_up_bingo = count_up_bingo + 1
168
-
169
- elif count == 4:
170
-
171
- count_up_reach = count_up_reach + 1
172
-
173
-
174
-
175
- '''斜め判定\'''
176
-
177
- diagonal_r = list(np.diag(df1))
178
-
179
- lst = [i for i in diagonal_r if isinstance(i, str)] # 文字列のみ
180
-
181
- cnt = len(lst)
182
-
183
- if cnt == 5:
184
-
185
- count_up_bingo = count_up_bingo + 1
186
-
187
- elif cnt == 4:
188
-
189
- count_up_reach = count_up_reach + 1
190
-
191
-
192
-
193
- '''斜め判定2/'''
194
-
195
- diagonal_l = list(np.diag(np.fliplr(df1)))
196
-
197
- lst = [i for i in diagonal_l if isinstance(i, str)] # 文字列のみ
198
-
199
- cnt2 = len(lst)
200
-
201
- if cnt2 == 5:
202
-
203
- count_up_bingo = count_up_bingo + 1
204
-
205
- elif cnt2 == 4:
206
-
207
- count_up_reach = count_up_reach + 1
208
-
209
-
210
-
211
-
212
-
213
- print('ビンゴ数:' + str(count_up_bingo))
214
-
215
- print('リーチ数:' + str(count_up_reach))
216
-
217
-
218
-
219
- else:
220
-
221
- print('')
222
-
223
- print(str(count_up) + '回目!')
224
-
225
- print('ボールの番号は' + str(b_num) + 'です。ハズレです!')
226
-
227
- print(df1)
228
-
229
- print('ーーーーーーーーーーーーーーーーーーーーーーーー')
230
-
231
- print('ビンゴ数:' + str(count_up_bingo))
232
-
233
- print('リーチ数:' + str(count_up_reach))
234
-
235
-
236
-
237
- if count_up == 75:
238
-
239
- print('')
240
-
241
- print('_人人人人人人人人人人人_')
242
-
243
- print('> ビンゴゲーム終了!! <')
244
-
245
- print(' ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄')
246
-
247
- ```
248
-
249
49
 
250
50
 
251
51
  ### 試したこと

5

インデント修正しました

2021/01/12 04:13

投稿

nre
nre

スコア35

test CHANGED
File without changes
test CHANGED
@@ -208,9 +208,11 @@
208
208
 
209
209
 
210
210
 
211
+
212
+
211
-   print('ビンゴ数:' + str(count_up_bingo))
213
+ print('ビンゴ数:' + str(count_up_bingo))
212
-
214
+
213
-   print('リーチ数:' + str(count_up_reach))
215
+ print('リーチ数:' + str(count_up_reach))
214
216
 
215
217
 
216
218
 

4

修正

2021/01/07 07:57

投稿

nre
nre

スコア35

test CHANGED
File without changes
test CHANGED
@@ -208,9 +208,9 @@
208
208
 
209
209
 
210
210
 
211
- print('ビンゴ数:' + str(count_up_bingo))
211
+   print('ビンゴ数:' + str(count_up_bingo))
212
-
212
+
213
- print('リーチ数:' + str(count_up_reach))
213
+   print('リーチ数:' + str(count_up_reach))
214
214
 
215
215
 
216
216
 

3

修正

2021/01/07 07:53

投稿

nre
nre

スコア35

test CHANGED
File without changes
test CHANGED
@@ -52,65 +52,195 @@
52
52
 
53
53
  ```python
54
54
 
55
-
55
+ import pandas as pd
56
+
56
-
57
+ import random
58
+
59
+ import numpy as np
60
+
61
+
62
+
63
+
64
+
65
+ '''ビンゴ表のリスト'''
66
+
67
+ b = random.sample(range(1, 16), k=5)
68
+
69
+ i = random.sample(range(16, 31), k=5)
70
+
71
+ n = random.sample(range(31, 46), k=5)
72
+
73
+ n[2] = 'FREE' #三行目の真ん中をFREEにする。
74
+
75
+ g = random.sample(range(46, 61), k=5)
76
+
77
+ o = random.sample(range(61, 76), k=5)
78
+
79
+ table = [b, i, n, g, o]
80
+
81
+
82
+
83
+
84
+
85
+ '''リストを表にして表示'''
86
+
87
+ df1 = pd.DataFrame(table,
88
+
89
+ index=['b', 'i', 'n', 'g', 'o'],
90
+
91
+ columns=['v', 'w', 'x', 'y', 'z'])
92
+
93
+
94
+
95
+
96
+
97
+ '''ビンゴのボール(1~75までの数字を用意し、シャッフルする)'''
98
+
99
+ num = list(range(1, 76))
100
+
101
+ random.shuffle(num)
102
+
103
+
104
+
105
+
106
+
107
+ '''各カウントアップ'''
108
+
57
- bingo_count = 0
109
+ count_up = 0
58
-
59
-
60
-
110
+
61
- for b_num in num:  #たまの数だけ繰り返し処理をする。(省略)
111
+ count_up_bingo = 0
112
+
62
-
113
+ count_up_reach = 0
114
+
115
+
116
+
117
+
118
+
63
- '''省略'''
119
+ '''各判定処理'''
120
+
64
-
121
+ for b_num in num:
122
+
123
+ count_up = count_up + 1
124
+
65
- if num in df1.values: #たまの数字が表にあった時に書き換える処理
125
+ if b_num in df1.values:
66
-
126
+
67
- df1 = df1.replace(num, '')
127
+ df1 = df1.replace(b_num, '{' + str(b_num) + '}')
68
128
 
69
129
  df = df1.astype(str)
70
130
 
131
+ print('')
132
+
71
- '''省略'''
133
+ print(str(count_up) + '回目!')
134
+
72
-
135
+ print('ボールの番号は' + str(b_num) + 'です。当たりなので穴を開けます!')
136
+
73
-
137
+ print(df1)
138
+
74
-
139
+ print('ーーーーーーーーーーーーーーーーーーーーーーーー')
75
-
76
-
140
+
141
+
142
+
77
- '''縦の判定'''
143
+ '''判定'''
78
144
 
79
145
  for c in df.columns:
80
146
 
81
- count = sum(df[c].str.endswith('}')) + sum(df[c] == 'カラ')  #ココで穴の空いた数字とカラをカウントしてその数が5であればカウントする。
147
+ count = sum(df[c].str.endswith('}')) + sum(df[c] == 'FREE')
82
-
148
+
83
- if count == 5:
149
+ if count == 5:
84
-
150
+
85
- bingo_count = bingo_count + 1
151
+ count_up_bingo = count_up_bingo + 1
86
-
87
- print(bingo_count)
88
152
 
89
153
  elif count == 4:
90
154
 
155
+ count_up_reach = count_up_reach + 1
156
+
157
+
158
+
159
+ '''行判定'''
160
+
161
+ for r in df.index:
162
+
163
+ count = sum(df.loc[r].str.endswith('}')) + sum(df.loc[r] == 'FREE')
164
+
165
+ if count == 5:
166
+
167
+ count_up_bingo = count_up_bingo + 1
168
+
169
+ elif count == 4:
170
+
171
+ count_up_reach = count_up_reach + 1
172
+
173
+
174
+
175
+ '''斜め判定\'''
176
+
177
+ diagonal_r = list(np.diag(df1))
178
+
179
+ lst = [i for i in diagonal_r if isinstance(i, str)] # 文字列のみ
180
+
91
- count = count + 1
181
+ cnt = len(lst)
182
+
92
-
183
+ if cnt == 5:
184
+
93
-
185
+ count_up_bingo = count_up_bingo + 1
186
+
94
-
187
+ elif cnt == 4:
188
+
189
+ count_up_reach = count_up_reach + 1
190
+
191
+
192
+
193
+ '''斜め判定2/'''
194
+
195
+ diagonal_l = list(np.diag(np.fliplr(df1)))
196
+
197
+ lst = [i for i in diagonal_l if isinstance(i, str)] # 文字列のみ
198
+
199
+ cnt2 = len(lst)
200
+
201
+ if cnt2 == 5:
202
+
203
+ count_up_bingo = count_up_bingo + 1
204
+
205
+ elif cnt2 == 4:
206
+
207
+ count_up_reach = count_up_reach + 1
208
+
209
+
210
+
211
+ print('ビンゴ数:' + str(count_up_bingo))
212
+
213
+ print('リーチ数:' + str(count_up_reach))
214
+
215
+
216
+
95
- #[out]
217
+ else:
96
-
218
+
97
-
219
+ print('')
98
-
220
+
99
-
221
+ print(str(count_up) + '回目!')
100
-
222
+
101
-
223
+ print('ボールの番号は' + str(b_num) + 'です。ハズレです!')
102
-
224
+
103
- 16
225
+ print(df1)
226
+
104
-
227
+ print('ーーーーーーーーーーーーーーーーーーーーーーーー')
228
+
229
+ print('ビンゴ数:' + str(count_up_bingo))
230
+
231
+ print('リーチ数:' + str(count_up_reach))
232
+
233
+
234
+
105
- 17
235
+ if count_up == 75:
106
-
107
- 18
236
+
108
-
109
- 19
110
-
111
- 20
237
+ print('')
238
+
112
-
239
+ print('_人人人人人人人人人人人_')
240
+
113
-
241
+ print('> ビンゴゲーム終了!! <')
242
+
243
+ print(' ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄')
114
244
 
115
245
  ```
116
246
 

2

処理の追加

2021/01/07 07:51

投稿

nre
nre

スコア35

test CHANGED
File without changes
test CHANGED
@@ -60,7 +60,21 @@
60
60
 
61
61
  for b_num in num:  #たまの数だけ繰り返し処理をする。(省略)
62
62
 
63
+ '''省略'''
64
+
65
+ if num in df1.values: #たまの数字が表にあった時に書き換える処理
66
+
67
+ df1 = df1.replace(num, '')
68
+
69
+ df = df1.astype(str)
70
+
71
+ '''省略'''
72
+
73
+
74
+
75
+
76
+
63
- '''縦の判定'''
77
+ '''縦の判定'''
64
78
 
65
79
  for c in df.columns:
66
80
 

1

誤表記の修正

2021/01/07 07:39

投稿

nre
nre

スコア35

test CHANGED
File without changes
test CHANGED
@@ -68,9 +68,9 @@
68
68
 
69
69
  if count == 5:
70
70
 
71
- count_up_bingo = count_up_bingo + 1
71
+ bingo_count = bingo_count + 1
72
72
 
73
- print(count_up_bingo)
73
+ print(bingo_count)
74
74
 
75
75
  elif count == 4:
76
76