import sys
if not 'makemigrations' in sys.argv:
... начинается поток ...
Как улучшить код?
import math
import operator
def calc():
op = input("Select an operator: + - * / ** √\n")
if op in ['√']:
num = float(input('Enter a number: '))
res = f'√{num} = {math.sqrt(num)}'
else:
num1 = float(input("Enter the first number...\n"))
num2 = float(input("Enter the second number...\n"))
res = {
'+': f'{num1} + {num2} = {operator.add(num1, num2)}',
'-': f'{num1} - {num2} = {operator.sub(num1, num2)}',
'*': f'{num1} * {num2} = {operator.mul(num1, num2)}',
'/': f'{num1} / {num2} = {operator.truediv(num1, num2)}',
'**': f'{num1} ** {num2} = {operator.pow(num1, num2)}',
}.get(op, 'Unknown operation')
print(res)
if __name__ == '__main__':
print("This is a simple calculator on python")
while True:
calc()
if input("Calculation finished. Do another? (Y/N)\n").lower() != 'y':
break
...
if z==1:
yr()
v=str(input("Вы хотите продолжить y-yes/n-no :"))
if v == 'y':
z=0
...
# Get the first 20 hits for: "Breaking Code" WordPress blog
from googlesearch import search
for url in search('"Breaking Code" WordPress blog', stop=20):
print(url)
import os
from selenium import webdriver
DRIVER_PATH = os.path.join('c:\\', 'utils', 'chromedriver.exe')
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('start-maximized')
options.add_argument('window-size=2048x5000')
browser = webdriver.Chrome(executable_path=DRIVER_PATH, options=options)
browser.get('https://lime-shop.ru/shops/moskva/')
browser.implicitly_wait(10)
for el in browser.find_elements_by_xpath("//div[@class='shops__place']"):
print(el.text)
print('-' * 30)
from Levenshtein import distance
HELLO = [x.lower() for x in
['start', 'Привет', 'Хай', 'Доброе утро', 'Эй', 'Добрый день', 'Добрый вечер']]
samples = ['превед!', 'ывафыва', 'добрый день!', 'хэй', 'бла-бла']
for im in samples:
print(f'> {im}')
if any(distance(im.lower(), x) < 4 for x in HELLO):
print('< Привет\n')
else:
print('< Я не понимаю\n')
> превед!
< Привет
> ывафыва
< Я не понимаю
> добрый день!
< Привет
> хэй
< Привет
> бла-бла
< Я не понимаю
Проблема в том, что после запуска командой flask run парсер отрабатывает, но ...