from datetime import datetime
def foo():
print('ok ')
start = datetime.now()
for i in range(100000000):
delta = datetime.now() - start
if delta.seconds > 0:
foo()
start = datetime.now()
call.data.split('.')[1]
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}")
item_db = cur.execute("SELECT * FROM direction_db WHERE id=(%s)" % row).fetchone()
for row in range(2....
but1= types.InlineKeyboardButton('Утром', callback_data='daypart|утро')
but2= types.InlineKeyboardButton('Днём', callback_data= 'daypart|день')
@bot.callback_query_handler(func=lambda call: call.data.split('|')[0]=='daypart')
with open('data.json') as f:
data = json.load(f)
class Author2(BaseModel):
name: str
class Book(BaseModel):
title: str
author2: Author2 | None
books = [Book(**book) for book in data]
markup = types.InlineKeyboardMarkup(row_width=8)
sq_s_g3 = f"SELECT * FROM '{player1}-{player2}'"
cursor.execute(sq_s_g3)
records = cursor.fetchall()
for row in records:
markup.add(types.InlineKeyboardButton(text = row[1], callback_data = row[0]))
def start(message):
# тут то, что должно отрабатывать при start
@bot.message_handler(commands=['start'])
def start_command(message):
start(message)
@bot.message_handler(commands=['starts'])
def starts_command(message):
start(message)
# Далее то, что должно отрабатывать при starts
@bot.message_handler(commands=['start', 'starts'])
def start_command(message):
# то, что должно обрабатываться при этих командах
def get_value_from_dict(dct, path):
if not path:
return
key = path[0]
new_path = path[1:]
if curr_value := dct.get(key, None):
if new_path:
if type(curr_value) == dict:
if new_path:
return get_value_from_dict(curr_value, new_path)
else:
return
else:
return curr_value
d={
"lvl1_1": {
"lvl2_1": {
"lvl3_1": "value",
"lvl3_2": {
"lvl4_1": "value"
},
"lvl2_2": "value"
}
}
}
print(get_value_from_dict(d, ["lvl1_1", "lvl2_1", "lvl3_2", "lvl4_1"]))