from random import randrange, random, randint
from itertools import repeat
pop = range(1, 11)
sch = 0
sch_2 = 0
for j in range(10):
z = []
sch += 1
for i in range(100):
a = randrange(2)
z.append(a)
for x in z:
if z[x] == z[x+1] == z[x+2]:
del z[x+3:-1]
print(z)
import random as rd
total_attempts = 0
for _ in range(10):
attempts = 0
last_result = None
counter = 0
results = []
while True:
current_result = rd.choice(["О", "P"])
results.append(current_result)
if current_result == last_result:
counter += 1
else:
counter = 1
last_result = current_result
attempts += 1
if counter == 3:
break
print(f"{' '.join(results)} (Попыток: {attempts})")
total_attempts +=attempts
print(f"Среднее количество попыток: {total_attempts / 10:.1f}")
from random import randint
attempts = []
for i in range(10):
res = []
while True:
res.append(randint(0, 1))
if len(res) >= 3 and (res[-1]==res[-2]==res[-3]):
break
s = ''.join(['О' if s else 'Р' for s in res])
print(f'{s} (попыток: {len(s)})')
attempts.append(len(s))
print(f'Среднее количество попыток: {sum(attempts) / len(attempts)}.')
import random
result = {}
for n in range(10):
experiment = []
while True:
experiment.append('О' if random.random() < 0.5 else 'Р')
for i in range(len(experiment) - 2):
if (experiment[i] == experiment[i+1]) and (experiment[i+1] == (experiment[i+2])):
break
else:
continue
break
result[f'Попытка Номер {n+1}'] = experiment
print(result)