回答編集履歴
2
blush up
answer
CHANGED
@@ -35,17 +35,13 @@
|
|
35
35
|
```python
|
36
36
|
import random
|
37
37
|
|
38
|
-
|
38
|
+
one = "1"*10
|
39
|
-
|
39
|
+
two = "2"*10
|
40
40
|
count_times = 0
|
41
41
|
|
42
42
|
for _ in range(100):
|
43
|
-
total = ""
|
44
|
-
for _ in range(100):
|
45
|
-
|
43
|
+
total = ''.join([str(random.randint(1,2)) for _ in range(100)])
|
46
|
-
total += str(coin)
|
47
|
-
|
44
|
+
count_times += (total.count(one)+total.count(two)+1)//2
|
48
|
-
count_times += 1.0
|
49
45
|
|
50
46
|
result = count_times / 100
|
51
47
|
print(result)
|
1
追記
answer
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
```python
|
2
|
-
#!/usr/bin/env python
|
3
|
-
# -*- coding: utf-8 -*-
|
4
2
|
import random
|
5
3
|
|
6
4
|
number = "1111111111"
|
@@ -31,4 +29,24 @@
|
|
31
29
|
|
32
30
|
元のソース`result == count_times // 100`だと
|
33
31
|
- 代入は`==`ではなく`=`
|
34
|
-
- 小数点の計算をしたいときは`//`ではなく`/`
|
32
|
+
- 小数点の計算をしたいときは`//`ではなく`/`
|
33
|
+
|
34
|
+
短くしてみた
|
35
|
+
```python
|
36
|
+
import random
|
37
|
+
|
38
|
+
number = "1111111111"
|
39
|
+
number_two = "2222222222"
|
40
|
+
count_times = 0
|
41
|
+
|
42
|
+
for _ in range(100):
|
43
|
+
total = ""
|
44
|
+
for _ in range(100):
|
45
|
+
coin = random.randint(1,2)
|
46
|
+
total += str(coin)
|
47
|
+
if number in total or number_two in total:
|
48
|
+
count_times += 1.0
|
49
|
+
|
50
|
+
result = count_times / 100
|
51
|
+
print(result)
|
52
|
+
```
|