#СозданиеПростогоЧатаНаPython
Код из видео:
server.py
import socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('localhost', 1111))
server.listen()
client, address = server.accept()
flag = True
while flag:
msg = client.recv(1024).decode('utf-8')
if msg == 'quit':
flag = False
else:
print(msg)
client.send(input('Server: ').encode('utf-8'))
client.close()
server.close()
client.py
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('localhost', 1111))
flag = True
while flag:
client.send(input('Я: ').encode('utf-8'))
msg = client.recv(1024).decode('utf-8')
if msg == 'quit':
flag = False
else:
print(msg)
client.close()
Код из видео:
server.py
import socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('localhost', 1111))
server.listen()
client, address = server.accept()
flag = True
while flag:
msg = client.recv(1024).decode('utf-8')
if msg == 'quit':
flag = False
else:
print(msg)
client.send(input('Server: ').encode('utf-8'))
client.close()
server.close()
client.py
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('localhost', 1111))
flag = True
while flag:
client.send(input('Я: ').encode('utf-8'))
msg = client.recv(1024).decode('utf-8')
if msg == 'quit':
flag = False
else:
print(msg)
client.close()
👍5
#ПростаяПроверкаНадёжностиПароляНаPython
Код из видео:
import string
password = input('Введите пароль: ')
upper_case = any([1 if i in string.ascii_uppercase else 0 for i in password])
lower_case = any([1 if i in string.ascii_lowercase else 0 for i in password])
special = any([1 if i in string.punctuation else 0 for i in password])
digits = any([1 if i in string.digits else 0 for i in password])
length = len(password)
if length >= 10:
length = True
else:
length = False
characters = [upper_case, lower_case, special, digits, length]
print(characters)
score = 0
for i in range(len(characters)):
if characters[i]:
score += 1
print('Надёжность пароля: %s из 5' % score)
Код из видео:
import string
password = input('Введите пароль: ')
upper_case = any([1 if i in string.ascii_uppercase else 0 for i in password])
lower_case = any([1 if i in string.ascii_lowercase else 0 for i in password])
special = any([1 if i in string.punctuation else 0 for i in password])
digits = any([1 if i in string.digits else 0 for i in password])
length = len(password)
if length >= 10:
length = True
else:
length = False
characters = [upper_case, lower_case, special, digits, length]
print(characters)
score = 0
for i in range(len(characters)):
if characters[i]:
score += 1
print('Надёжность пароля: %s из 5' % score)
👍4
#ПреобразованиеКоординатВГеографическиеМестоположенияСПомощьюPython
Код из видео:
from geopy import Nominatim
coordinates = '73.783575, 93.008677'
nominaltim = Nominatim(user_agent='user')
location = nominaltim.reverse(coordinates)
print(location)
Код из видео:
from geopy import Nominatim
coordinates = '73.783575, 93.008677'
nominaltim = Nominatim(user_agent='user')
location = nominaltim.reverse(coordinates)
print(location)
👍5
#ГолосовойПомощникНаPython
Код из видео:
import pyttsx3
import speech_recognition as sr
def listen_command():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Скажите команду: ')
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration=1)
audio = r.listen(source)
try:
our_speech = r.recognize_google(audio, language='ru-RU')
print('Вы сказали: ' + our_speech)
return our_speech
except sr.UnknownValueError:
return 'Ошибка'
except sr.RequestError:
return 'Ошибка'
def do_this_message(message):
message = message.lower()
if 'привет' in message:
say_message('Привет!')
elif 'как дела' in message:
say_message('Хорошо')
elif 'пока' in message:
say_message('Пока')
exit()
else:
say_message('Команда не распознана!')
def say_message(message):
engine.say(message)
engine.runAndWait()
print(message)
engine = pyttsx3.init()
engine.setProperty('rate', 150)
engine.setProperty('volume', 1)
while True:
command = listen_command()
do_this_message(command)
Код из видео:
import pyttsx3
import speech_recognition as sr
def listen_command():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Скажите команду: ')
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration=1)
audio = r.listen(source)
try:
our_speech = r.recognize_google(audio, language='ru-RU')
print('Вы сказали: ' + our_speech)
return our_speech
except sr.UnknownValueError:
return 'Ошибка'
except sr.RequestError:
return 'Ошибка'
def do_this_message(message):
message = message.lower()
if 'привет' in message:
say_message('Привет!')
elif 'как дела' in message:
say_message('Хорошо')
elif 'пока' in message:
say_message('Пока')
exit()
else:
say_message('Команда не распознана!')
def say_message(message):
engine.say(message)
engine.runAndWait()
print(message)
engine = pyttsx3.init()
engine.setProperty('rate', 150)
engine.setProperty('volume', 1)
while True:
command = listen_command()
do_this_message(command)
👍6
#АнимацияБулевыхОперацийНаPython
Код из видео:
from manim import *
class Example(Scene):
def construct(self):
ellipse1 = Ellipse(width=4, height=5, fill_opacity=0.5, color=BLUE, stroke_width=10).move_to(LEFT)
ellipse2 = ellipse1.copy().set_color(color=RED).move_to(RIGHT)
bool_ops_text = MarkupText('<u>Example</u>').next_to(ellipse1, UP * 3)
ellipse_group = Group(bool_ops_text, ellipse1, ellipse2).move_to(LEFT * 3)
self.play(FadeIn(ellipse_group))
i = Intersection(ellipse1, ellipse2, color=GREEN, fill_opacity=0.5)
self.play(i.animate.scale(0.25).move_to(RIGHT * 5 + UP * 2.5))
intersaction_text = Text('Intersection', font_size=23).next_to(i, UP)
self.play(FadeIn(intersaction_text))
u = Union(ellipse1, ellipse2, color=ORANGE, fill_opacity=0.5)
union_text = Text('Union', font_size=23)
self.play(u.animate.scale(0.3).next_to(i, DOWN, buff=union_text.height * 3))
union_text.next_to(u, UP)
self.play(FadeIn(union_text))
e = Exclusion(ellipse1, ellipse2, color=YELLOW, fill_opacity=0.5)
exclusion_text = Text('Exclusion', font_size=23)
self.play(e.animate.scale(0.3).next_to(u, DOWN, buff=exclusion_text.height * 3.5))
exclusion_text.next_to(e, UP)
self.play(FadeIn(exclusion_text))
d = Difference(ellipse1, ellipse2, color=PINK, fill_opacity=0.5)
difference_text = Text('Difference', font_size=23)
self.play(d.animate.scale(0.3).next_to(u, LEFT, buff=difference_text.height * 3.5))
difference_text.next_to(d, UP)
self.play(FadeIn(difference_text))
Код из видео:
from manim import *
class Example(Scene):
def construct(self):
ellipse1 = Ellipse(width=4, height=5, fill_opacity=0.5, color=BLUE, stroke_width=10).move_to(LEFT)
ellipse2 = ellipse1.copy().set_color(color=RED).move_to(RIGHT)
bool_ops_text = MarkupText('<u>Example</u>').next_to(ellipse1, UP * 3)
ellipse_group = Group(bool_ops_text, ellipse1, ellipse2).move_to(LEFT * 3)
self.play(FadeIn(ellipse_group))
i = Intersection(ellipse1, ellipse2, color=GREEN, fill_opacity=0.5)
self.play(i.animate.scale(0.25).move_to(RIGHT * 5 + UP * 2.5))
intersaction_text = Text('Intersection', font_size=23).next_to(i, UP)
self.play(FadeIn(intersaction_text))
u = Union(ellipse1, ellipse2, color=ORANGE, fill_opacity=0.5)
union_text = Text('Union', font_size=23)
self.play(u.animate.scale(0.3).next_to(i, DOWN, buff=union_text.height * 3))
union_text.next_to(u, UP)
self.play(FadeIn(union_text))
e = Exclusion(ellipse1, ellipse2, color=YELLOW, fill_opacity=0.5)
exclusion_text = Text('Exclusion', font_size=23)
self.play(e.animate.scale(0.3).next_to(u, DOWN, buff=exclusion_text.height * 3.5))
exclusion_text.next_to(e, UP)
self.play(FadeIn(exclusion_text))
d = Difference(ellipse1, ellipse2, color=PINK, fill_opacity=0.5)
difference_text = Text('Difference', font_size=23)
self.play(d.animate.scale(0.3).next_to(u, LEFT, buff=difference_text.height * 3.5))
difference_text.next_to(d, UP)
self.play(FadeIn(difference_text))
#ПрячемФайлыВJpegИзображениеСПомощьюPython
Код из видео:
Прячем файл в изображение:
with open('photo.jpg', 'ab') as f, open('start.zip', 'rb') as s:
f.write(s.read())
Достаём канал:
with open('photo.jpg', 'rb') as f:
content = f.read()
offset = content.index(bytes.fromhex('FFD9'))
f.seek(offset + 2)
with open('newfile.zip', 'wb') as s:
s.write(f.read())
Код из видео:
Прячем файл в изображение:
with open('photo.jpg', 'ab') as f, open('start.zip', 'rb') as s:
f.write(s.read())
Достаём канал:
with open('photo.jpg', 'rb') as f:
content = f.read()
offset = content.index(bytes.fromhex('FFD9'))
f.seek(offset + 2)
with open('newfile.zip', 'wb') as s:
s.write(f.read())
🎉2