Форум сайта python.su
QComboBox { border: 2px solid #f66867; border-radius: 30px; background-color: #22222e; color: white; padding-left: 35px; } QListView { background-color: #f66867; border-radius: 3px; selection-background-color: #fa4244; } QComboBox::drop-down { border-radius: 3px; }
self.comboBox_3.setEditable(False) self.comboBox_3.setObjectName("comboBox_3") self.comboBox_3.addItem("") self.comboBox_3.addItem("") self.comboBox_3.addItem("") self.comboBox_4 = QtWidgets.QComboBox(self.centralwidget) self.comboBox_4.setGeometry(QtCore.QRect(300, 320, 381, 61)) font = QtGui.QFont() font.setFamily("Montserrat") font.setPointSize(14) font.setBold(True) font.setWeight(75) self.comboBox_4.setFont(font) self.comboBox_4.setStyleSheet("QComboBox {\n" " border: 2px solid #f66867;\n" " border-radius: 30px;\n" " background-color: #22222e;\n" " color: white;\n" " padding-left: 35px;\n" "}\n" "\n" "QComboBox QListView {\n" " background-color: #f66867;\n" " border-radius: 3px;\n" " selection-background-color: #fa4244;\n" "}\n" "\n" "QComboBox::drop-down {\n" " border-radius: 3px;\n" "}")
"QComboBox QListView {\n" " background-color: #f66867;\n" " border-radius: 3px;\n" " selection-background-color: #fa4244;\n" "}\n"
from dataclasses import dataclass from typing import List, Union from validated_dc import ValidatedDC # Some combinations of List and Union @dataclass class Foo(ValidatedDC): value: Union[int, List[int]] @dataclass class Bar(ValidatedDC): foo: Union[Foo, List[Foo]] # --- Valid input --- foo = {'value': 1} instance = Bar(foo=foo) assert instance.get_errors() is None assert instance == Bar(foo=Foo(value=1)) foo = {'value': [1, 2]} instance = Bar(foo=foo) assert instance.get_errors() is None assert instance == Bar(foo=Foo(value=[1, 2])) foo = [{'value': 1}, {'value': 2}] instance = Bar(foo=foo) assert instance.get_errors() is None assert instance == Bar(foo=[Foo(value=1), Foo(value=2)]) foo = [{'value': [1, 2]}, {'value': [3, 4]}] instance = Bar(foo=foo) assert instance.get_errors() is None assert instance == Bar(foo=[Foo(value=[1, 2]), Foo(value=[3, 4])]) # --- Invalid input --- foo = {'value': 'S'} instance = Bar(foo=foo) assert instance.get_errors() assert instance == Bar(foo={'value': 'S'}) # fix instance.foo['value'] = 1 assert instance.is_valid() assert instance.get_errors() is None assert instance == Bar(foo=Foo(value=1)) foo = [{'value': [1, 2]}, {'value': ['S', 4]}] instance = Bar(foo=foo) assert instance.get_errors() assert instance == Bar(foo=[{'value': [1, 2]}, {'value': ['S', 4]}]) # fix instance.foo[1]['value'][0] = 3 assert instance.is_valid() assert instance.get_errors() is None assert instance == Bar(foo=[Foo(value=[1, 2]), Foo(value=[3, 4])]) # --- get_errors() --- foo = {'value': 'S'} instance = Bar(foo=foo) print(instance.get_errors()) # { # 'foo': [ # # An unsuccessful attempt to use the dictionary to create a Foo instance # InstanceValidationError( # value_repr="{'value': 'S'}", # value_type=<class 'dict'>, # annotation=<class '__main__.Foo'>, # exception=None, # errors={ # 'value': [ # BasicValidationError( # because the str isn't an int # value_repr='S', value_type=<class 'str'>, # annotation=<class 'int'>, exception=None # ), # BasicValidationError( # and the str is not a list of int # value_repr='S', value_type=<class 'str'>, # annotation=typing.List[int], exception=None # ) # ] # } # ), # BasicValidationError( # the dict is not a list of Foo # value_repr="{'value': 'S'}", # value_type=<class 'dict'>, # annotation=typing.List[__main__.Foo], # exception=None # ) # ] # }
Задача: Даны две функции y=x**2 и y=x**2+5. Выбираем интервал для x от -5 до +5 с шагом 1. Необходимо найти в этом интервале такие значения y, чтобы ломаная, построенная из полученных новых точек (x,y - целые числа, шаг 1 от -5 до +5) ломаная линия находилась строго между этими функциями и угол поворота был не меньше 110 градусов. Результат программы - можно или нет построить такую ломаную и один из вариантов такой ломаной со значениями x,y при шаге 1 по оси х. . Эта задача близка к управлению оборудованием по данным датчиков.
import math def f(x): return x * x * x + 2 * x * x - 8 * x + 1 + 2 * math.sin(x) + 15 * math.cos(x) a = -5 b = 5 delta = 0.001 h = 0.05 x = a while x <= b: if f(x) * f(x * delta) <= 0: print(x + delta / 2) x += h
import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression pd.options.display.max_rows = 1000 data = pd.read_csv("https://video.ittensive.com/python-advanced/data-9753-2019-07-25.utf.csv", delimiter = ";") data = data.groupby("Year").filter(lambda x : x["UnemployedTotal"].count() < 6) data["Year"] = data["Year"].astype("category") data_group = data.groupby("Year").mean() x = np.array(data_group.index).reshape(len(data_group.index),1) y = np.array(data_group["UnemployedDisabled"]/data_group["UnemployedTotal"]*100).reshape(len(data_group.index),1) model = LinearRegression() model.fit(x, y) plt.scatter(x,y , color ="orange") x = np.append(x,[2020]).reshape(len(data_group.index)+1,1) plt.plot(x, model.predict(x), color = "blue", linewidth = 3) plt.show() print(model.predict(np.array(2020).reshape(1,1))) #print(data_group)