回答編集履歴
2
blush up
test
CHANGED
@@ -72,9 +72,9 @@
|
|
72
72
|
|
73
73
|
|
74
74
|
|
75
|
-
n
|
75
|
+
one = "1"*10
|
76
76
|
|
77
|
-
|
77
|
+
two = "2"*10
|
78
78
|
|
79
79
|
count_times = 0
|
80
80
|
|
@@ -82,17 +82,9 @@
|
|
82
82
|
|
83
83
|
for _ in range(100):
|
84
84
|
|
85
|
-
total =
|
85
|
+
total = ''.join([str(random.randint(1,2)) for _ in range(100)])
|
86
86
|
|
87
|
-
for _ in range(100):
|
88
|
-
|
89
|
-
coin = random.randint(1,2)
|
90
|
-
|
91
|
-
total += str(coin)
|
92
|
-
|
93
|
-
i
|
87
|
+
count_times += (total.count(one)+total.count(two)+1)//2
|
94
|
-
|
95
|
-
count_times += 1.0
|
96
88
|
|
97
89
|
|
98
90
|
|
1
追記
test
CHANGED
@@ -1,8 +1,4 @@
|
|
1
1
|
```python
|
2
|
-
|
3
|
-
#!/usr/bin/env python
|
4
|
-
|
5
|
-
# -*- coding: utf-8 -*-
|
6
2
|
|
7
3
|
import random
|
8
4
|
|
@@ -65,3 +61,43 @@
|
|
65
61
|
- 代入は`==`ではなく`=`
|
66
62
|
|
67
63
|
- 小数点の計算をしたいときは`//`ではなく`/`
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
短くしてみた
|
68
|
+
|
69
|
+
```python
|
70
|
+
|
71
|
+
import random
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
number = "1111111111"
|
76
|
+
|
77
|
+
number_two = "2222222222"
|
78
|
+
|
79
|
+
count_times = 0
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
for _ in range(100):
|
84
|
+
|
85
|
+
total = ""
|
86
|
+
|
87
|
+
for _ in range(100):
|
88
|
+
|
89
|
+
coin = random.randint(1,2)
|
90
|
+
|
91
|
+
total += str(coin)
|
92
|
+
|
93
|
+
if number in total or number_two in total:
|
94
|
+
|
95
|
+
count_times += 1.0
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
result = count_times / 100
|
100
|
+
|
101
|
+
print(result)
|
102
|
+
|
103
|
+
```
|