line = 'abdrakadabra'
etalon = 'abrakadabra'
x = 0
mistake = 0
new_line=''
try:
for _ in line:
if _ == etalon[x]:
new_line += _
else:
mistake = x
x-=1
x+=1
except:
pass
print(mistake+1)
Вообщем, мне нужен код
@bot.message_handler(commands=["start"])
def welcome(message):
#Сделаем клавиатуру
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = types.KeyboardButton("Как дела?")
item2 = types.KeyboardButton("Я знаю что ты вор!")
item3 = types.KeyboardButton("Есть хочешь?")
item4 = types.KeyboardButton("А спать хочешь?")
item5 = types.KeyboardButton("Что-то секретное...")
markup.add(item1, item2, item5)
bot.send_message(message.chat.id, "Привет, {0.first_name}!\nЯ - <b>{1.first_name}</b>. Напиши мне что-то, может познакомимся, да?".format(message.from_user, bot.get_me()),
parse_mode='html', reply_markup=markup)
start_page_buttons=["Как дела?","Я знаю что ты вор!","Есть хочешь?","А спать хочешь?", "Что-то секретное..."]
def start_buttons_create():
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
for _ in start_page_buttons:
keyboard.add(_)
return keyboard
bot.send_message(message.chat.id, "Привет, {0.first_name}!\nЯ - <b>{1.first_name}</b>. Напиши мне что-то, может познакомимся, да?".format(message.from_user, bot.get_me()),
parse_mode='html', reply_markup=start_buttons_create())
s = 'Как вывети два первых слова из предложения на питоне?'
print(s.split()[:2])
import pathlib
folder = pathlib.Path().absolute()
video = fr'{folder}\VIDEO_{time.strftime("%m%d%Y_%H%M%S")}.avi'
from tkinter import *
import ttk # pip install pyttk
root = Tk()
variable = StringVar(root)
variable.set("Your choise")
combobox = ttk.Combobox(root, textvariable=variable, values=[*[f'Your number is {i}' for i in range(1,7)]*20])
combobox.pack()
root.mainloop()
bot.send_message (message.chat.id, 'Напиши, и я запомню', callback_data = 'i know')
markup4 = types.InlineKeyboardMarkup()
item1 = types.InlineKeyboardButton("Разозлиться", callback_data='good1')
item2 = types.InlineKeyboardButton("Вытереть слезки", callback_data='bad1')
markup4.add(item1, item2)
bot.send_message(message.chat.id, text='Выбрать действие:', reply_markup=markup4)
import numpy as np
import cv2
from mss import mss
from PIL import Image
import threading
from pygame import mixer
class MyMss():
def __init__(self,mss,mixer):
super(MyMss,self).__init__()
self.bounding_box = {'top': 100, 'left': 0, 'width': 400, 'height': 300}
self.mss = mss
self.mixer = mixer
def _grab(self):
while True:
sct_img = self.mss.grab(self.bounding_box)
cv2.imshow('screen', np.array(sct_img))
if (cv2.waitKey(1) & 0xFF) == ord('q'):
cv2.destroyAllWindows()
break
def start_grab(self):
thread = threading.Thread(target=self._grab)
thread.start()
def _music(self):
self.mixer.init()
self.mixer.music.load('fon.mp3')
self.mixer.music.play()
def play_music(self):
m_th = threading.Thread(target=self._music)
m_th.start()
sct = MyMss(mss(),mixer)
sct.start_grab()
sct.play_music()
def process_age_step(message):
try:
chat_id = message.chat.id
age = message.text
if not age.isdigit():
msg = bot.reply_to(message, 'Age should be a number. How old are you?')
bot.register_next_step_handler(msg, process_age_step)
return
user = user_dict[chat_id]
user.age = age
markup = types.ReplyKeyboardMarkup(one_time_keyboard=True)
markup.add('Male', 'Female')
msg = bot.reply_to(message, 'What is your gender', reply_markup=markup)
bot.register_next_step_handler(msg, process_sex_step)
except Exception as e:
bot.reply_to(message, 'oooops')
def process_sex_step(message):
try:
chat_id = message.chat.id
sex = message.text
keybord = keybord_yes_or_no()
bot.send_message(massage.from_user.id, text= quest, reply_markup=keybord)
def day_btns():
days = types.InlineKeyboardMarkup(row_width=7)
days.add(*[types.InlineKeyboardButton(text='Day '+str(i),callback_data='call'+str(i)) for i in range(1,8)])
return days
#Пример использования
bot.send_message(message.chat.id,'Days of week',reply_markup=day_btns())
#Хватает и одной строки
from time import sleep
import threading
def sp():
while True:
for _ in range(1,11):
print(f'Itaration {_}')
sleep(0.2)
print('10 second PAUSE')
sleep(3)#TODO paste your delay
my_thread1 = threading.Thread(target=sp)
my_thread1.start()
my_thread1.join()
import requests as s
from time import sleep
import threading
def main():
web = ['https://google.com','https://habr.com','https://vk.com']
for i in web:
try:
r = s.get(i)
except:
print('error')
sleep(5)
s.get(i)
my_thread1 = threading.Thread(target=main)
my_thread1.start()
my_thread2 = threading.Thread(target=main)
my_thread2.start()