diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/homework_7.py b/homework_7.py new file mode 100644 index 0000000..086c9dc --- /dev/null +++ b/homework_7.py @@ -0,0 +1,176 @@ +# # Task 1 +# +# +# class Matrix: +# my_list = [] +# +# def __init__(self, my_list): +# self.list = my_list +# +# def __str__(self): +# print(' ') +# res = '' +# for i in range(len(self.list)): +# res += str(self.list[i]) + '\n' +# return res +# +# def __add__(self, other): +# res = [] +# a = self.list +# b = other.list +# for i in range(len(a)): +# if i >= len(b): +# b.append([]) +# res.append([]) +# for j in range(len(a[i])): +# if j >= len(b[i]): +# b[i].append(0) +# res[i].append(a[i][j] + b[i][j]) +# return Matrix(res) +# +# +# matrix1 = Matrix([[1, 5, 9], [1, 4, 5], [4, 8, 9]]) +# print(matrix1) +# +# matrix2 = Matrix([[1, 5, 7], [6, 8, 9]]) +# print(matrix2) +# +# matrix3 = matrix1 + matrix2 +# print(matrix3) + +# # Task 2 +# +# +# from abc import ABC, abstractmethod +# +# +# class Clothes(ABC): +# +# def __init__(self, name): +# self.n = name +# self.s = None +# +# @property +# def name(self): +# return self.n +# +# @abstractmethod +# def get_s(self): +# pass +# +# class Coat(Clothes): +# def __init__(self, name, v): +# super().__init__(name) +# self.v = v +# +# @property +# def v(self): +# return self.__v +# +# @v.setter +# def v(self, v): +# if v < 30: +# self.__v = 30 +# elif v > 62: +# self.__v = 62 +# else: +# self.__v = v +# +# def get_s(self): +# self.s = (self.__v / 6.5) + 0.5 +# return self.s +# +# +# class Suit(Clothes): +# def __init__(self, name, h): +# super().__init__(name) +# self.h = h +# +# @property +# def h(self): +# return self.__h +# +# @h.setter +# def h(self, h): +# if h < 120: +# self.__h = 120 +# elif h > 220: +# self.__h = 220 +# else: +# self.__h = h +# +# def get_s(self): +# self.s = (2 * self.__h) + 0.3 +# return self.s +# +# +# class Collection: +# def __init__(self): +# self.my_list = [] +# self.s = 0 +# +# def add_clothes(self, my_clothes: Clothes): +# self.my_list.append(my_clothes) +# self.s += my_clothes.get_s() +# +# def __str__(self): +# my_string = '' +# for el in self.my_list: +# my_string += 'Площадь ткани для ' + el.name + ' равна ' + str(round(el.get_s(), 2)) + '\n' +# my_string = my_string + 'Суммарная площадь ткани для всей коллекции равна ' + str(round(self.s, 2)) +# return my_string +# +# +# m_list = Collection() +# m_list.add_clothes(Coat('green coat', 46)) +# m_list.add_clothes(Suit('striped suit', 182)) +# # print(m_list.s) +# print(m_list) + + +# Task 3 + +class Cell: + def __init__(self, n): + self.n = n + + def __str__(self): + return f' n = {self.n}' + + def __add__(self, other): + return Cell(self.n + other.n) + + def __sub__(self, other): + if self.n > other.n: + return Cell(self.n - other.n) + else: + return 'Разность количества ячеек двух клеток должна быть больше нуля' + + def __mul__(self, other): + return Cell(self.n * other.n) + + def __truediv__(self, other): + if other.n != 0: + return Cell(self.n // other.n) + else: + return 'Количество ячеек клетки - делителя должна быть больше нуля' + + def make_order(self, number): + if number > 0: + k = self.n // number + ost = self.n % number + my_str = '*' * number + last_str = '*' * ost + for i in range(k): + print(my_str) + print(last_str) + + +one = Cell(15) +two = Cell(4) +print(one + two) +print(one - two) +print(one * two) +print(one / two) +one.make_order(14) + diff --git a/homework_8.py b/homework_8.py new file mode 100644 index 0000000..5ee0008 --- /dev/null +++ b/homework_8.py @@ -0,0 +1,223 @@ +# # Task 1 +# +# +# class Date: +# def __init__(self, date): +# self.date = date +# +# @classmethod +# def num_date(cls, obj): +# my_date = obj.date.split('-') +# print(f'число = {int(my_date[0])}, месяц = {int(my_date[1])}, год = {int(my_date[2])}') +# +# +# @staticmethod +# def correct_date(obj): +# my_date = obj.date.split('-') +# list_31 = [1, 3, 5, 7, 8, 10, 12] +# d = int(my_date[0]) +# m = int(my_date[1]) +# y = int(my_date[2]) +# if m == 2 and y % 4 == 0 and d > 29: +# print('В феврале високосного года только 29 дней') +# elif m == 2 and y % 4 != 0 and d > 28: +# print('В феврале невисокосного года только 28 дней') +# elif m in list_31 and 1 <= d <= 31 and y > 0: +# print('Введенная дата верна') +# elif m not in list_31 and 1 <= d <= 30 and y > 0: +# print(f'Введенная дата верна.') +# else: +# print('Введенная дата не верна') +# +# +# a = Date('35-03-2021') +# b = Date('01-04-2015') +# Date.num_date(a) +# Date.correct_date(a) +# Date.num_date(b) +# Date.correct_date(b) + + +# # Task 2 +# +# class DelError(Exception): +# def __init__(self, txt): +# self.txt = txt +# +# +# a, b = list(map(int, input('Введите делимое и делитель через пробел ').split())) +# +# try: +# if b == 0: +# raise DelError("Делить на ноль нельзя!") +# except (ZeroDivisionError, DelError) as err: +# print(err) +# print(1) +# else: +# print(round(a / b, 2)) + + +##Task 3 + + +# class NumError(Exception): +# def __init__(self, txt): +# self.txt = txt +# +# my_list = [] +# while True: +# a = input('Введите элемент списка, для выхода stop ').split() +# stop_det = 0 +# for el in a: +# try: +# for j in range(len(el)): +# if ord(el[j]) < 48 or ord(el[j]) > 57: +# raise NumError('Необходимо вводить только числа') +# except NumError as err: +# print(err) +# if el.title() == 'Stop': +# stop_det = 1 +# break +# else: +# my_list.append(el) +# if stop_det == 1: +# break +# +# print(my_list) + +# Task 4, 5, 6 + + +from abc import ABC, abstractmethod + + +class Hardware(ABC): + def __init__(self, name, port): + self.name = name + self.port = port + + @abstractmethod + def __str__(self): + pass + + +class Printer(Hardware): + def __init__(self, name, port, color): + super().__init__(name, port) + self.color = color + + @property + def color(self): + return self.__color + + @color.setter + def color(self, bool): + if bool in ['True', 'true', 'Yes', 'yes', 'y', 'Y', 'да', 'Да', '+', 'color', 'Color', True]: + self.__color = True + else: + self.__color = False + + def __str__(self): + if self.__color: + return 'Color printer ' + str(self.name) + ' on a tcp port ' + str(self.port) + else: + return 'Black&White printer ' + str(self.name) + ' on a tcp port ' + str(self.port) + + +class Monitor(Hardware): + def __init__(self, name, port, w, h): + super().__init__(name, port) + self.resolution = str(w) + 'x' + str(h) + + def __str__(self): + return 'Monitor ' + str(self.name) + ' on a ' + str(self.port) + ' port ' + self.resolution + + +class Scanner(Hardware): + def __init__(self, name, port): + super().__init__(name, port) + + def __str__(self): + return 'Scanner ' + str(self.name) + ' on a ' + str(self.port) + ' port' + + +class Warehouse: + def __init__(self): + self.hw_list = [] + self.count = 0 + + def get_count(self): + return self.count + + def add_hardware(self, my_hardware: Hardware, qtty): + try: + for i in range(qtty): + self.hw_list.append(my_hardware) + self.count += qtty + except TypeError: + print('Quantity shall be an integer number') + + def move(self, other, ordnum): + if len(self.hw_list) >= ordnum: + other.add_hardware(self.hw_list[ordnum], 1) + print(f'{self.hw_list[ordnum]} is moved successfully') + del self.hw_list[ordnum] + self.count -= 1 + else: + print('Hardware index is out of range') + + def __str__(self): + my_string = '' + for el in self.hw_list: + my_string += str(el) + '\n' + my_string = my_string + 'Total amount of hardware on central warehouse: ' + str(self.count) + return my_string + + +central_wh = Warehouse() +central_wh.add_hardware(Printer('LSB-20', 'usb', 'Да'), 'two') +central_wh.add_hardware(Monitor('Viewsonic', 'pci-e', 640, 480), 5) +central_wh.add_hardware(Scanner('HP', 'usb'), 3) +IT = Warehouse() +Accounting = Warehouse() + +central_wh.move(IT, 4) +central_wh.move(Accounting, 9) + +print('IT:') +print(IT) +print('Accounting:') +print(Accounting) +print('Whs:') +print(central_wh) + +# # Task 7 +# +# class Complex: +# def __init__(self, re, im): +# self.re = re +# self.im = im +# +# def __add__(self, other): +# return Complex(self.re + other.re, self.im + other.im) +# +# def __mul__(self, other): +# return Complex(self.re * other.re - self.im * other.im, self.re * other.im + other.re * self.im) +# +# def __str__(self): +# if self.im > 0: +# return str(self.re) + '+' + str(self.im) + 'i' +# elif self.im < 0: +# return str(self.re) + str(self.im) + 'i' +# else: +# return str(self.re) +# +# +# z = Complex(5, 0) +# z1 = Complex(5, 4) +# z2 = Complex(5, -3) +# print(z) +# print(z1) +# print(z2) +# print(z1 + z2) +# print(z1 * z2)