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)
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 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}")
import telebot
from telebot import types
bot = telebot.TeleBot('токен')
@bot.message_handler(commands=['start'])
def start(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton('Начать')
btn2 = types.KeyboardButton('Помощь')
markup.add(btn1, btn2)
bot.send_message(message.chat.id, f'Привет, я тестовый бот, пока что, я ничего не умею', reply_markup=markup)
@bot.message_handler(content_types=['text'])
def com(message):
if message.text == 'Начать':
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn3 = types.KeyboardButton('Узнать свой ID')
btn4 = types.KeyboardButton('Поздороваться')
btn5 = types.KeyboardButton('Смешная фотография')
markup.add(btn3, btn4, btn5)
bot.send_message(message.chat.id, 'вот команды, доступные для ботика', reply_markup=markup)
elif message.text == 'Поздороваться':
bot.send_message(message.chat.id, 'Здарова лох')
bot.polling(none_stop=True)