diff --git a/#1.py b/#1.py new file mode 100644 index 0000000..7f445a8 --- /dev/null +++ b/#1.py @@ -0,0 +1,26 @@ +class Data: + data = '' + + def __init__(self, date): + Data.data = date + + @staticmethod + def numbers(date): + n = {} + for i, v in enumerate(date.split('.')): + n[i] = v + return f'день {n[0]} из 31, месяц {n[1]} из 12' if int(n[0]) < 31 and int(n[1]) < 13 else None + + @classmethod + def ints(cls): + fn = {} + for m, k in enumerate(cls.data.split('.')): + fn[m] = k + return fn[0], fn[1], fn[2] + + def my_method1(self): + return (Data.numbers(Data.data), Data.ints()) if Data.numbers(Data.data) else 'Дата введена неверно' + + +d = Data('12.03.98') +print(d.my_method1()) diff --git a/#2.py b/#2.py new file mode 100644 index 0000000..08e95f4 --- /dev/null +++ b/#2.py @@ -0,0 +1,15 @@ +class ZeroDivision(Exception): + def __init__(self): + self.txt = 'На ноль делить нелязя!' + + +a = int(input()) +b = int(input()) +try: + if b == 0: + raise ZeroDivision +except ZeroDivision as err: + print(err) +else: + print(a / b) + diff --git a/#3.py b/#3.py new file mode 100644 index 0000000..5f2458c --- /dev/null +++ b/#3.py @@ -0,0 +1,19 @@ +class OnlyNumber(Exception): + def __init__(self, txt): + self.txt = txt + + +x = input() +a = [] +while x != 'stop': + try: + if not x.isnumeric(): + raise OnlyNumber('Необходимо ввести число!') + else: + a.append(int(x)) + except OnlyNumber as err: + print(err) + x = input() +print(a) + + diff --git a/#4.py b/#4.py new file mode 100644 index 0000000..f997115 --- /dev/null +++ b/#4.py @@ -0,0 +1,36 @@ +class Stock: + pass + + +class Equipment(Stock): + all_equipment = 0 + + +class Printer(Equipment): + counter = 0 + + def __init__(self, id, price): + Equipment.all_equipment += 1 + Printer.counter += 1 + self.price = price + self.id = id + + +class Scanner(Equipment): + counter = 0 + + def __init__(self, id, price): + Equipment.all_equipment += 1 + Scanner.counter += 1 + self.price = price + self.id = id + + +class Xerox(Equipment): + counter = 0 + + def __init__(self, id, price): + Equipment.all_equipment += 1 + Xerox.counter += 1 + self.price = price + self.id = id diff --git a/#5.py b/#5.py new file mode 100644 index 0000000..fe50c12 --- /dev/null +++ b/#5.py @@ -0,0 +1,80 @@ +class Stock: + items = {'Printer': [0], 'Scanner': [0], 'Xerox': [0]} + + @staticmethod + def count(type): + print(Stock.items[type][0]) + + +class Equipment(Stock): + all_equipment = 0 + + +class Printer(Equipment): + counter = 0 + + def __init__(self, name, price): + Equipment.all_equipment += 1 + Printer.counter += 1 + self.price = price + self.name = name + self.location = None + + def stock(self): + Stock.items['Printer'].append({self.name: self.price}) + Stock.items['Printer'][0] += 1 + self.location = 'Stock' + + def move(self, where): + self.location = where + Stock.items['Printer'].remove({self.name: self.price}) + Stock.items['Printer'][0] -= 1 + + +class Scanner(Equipment): + counter = 0 + + def __init__(self, name, price): + Equipment.all_equipment += 1 + Scanner.counter += 1 + self.price = price + self.name = name + self.location = None + + def stock(self): + Stock.items['Scanner'].append({self.name: self.price}) + Stock.items['Scanner'][0] += 1 + self.location = 'Stock' + + def move(self, where): + self.location = where + Stock.items['Scanner'].remove({self.name: self.price}) + Stock.items['Scanner'][0] -= 1 + + +class Xerox(Equipment): + counter = 0 + + def __init__(self, name, price): + Equipment.all_equipment += 1 + Xerox.counter += 1 + self.price = price + self.name = name + self.location = None + + def stock(self): + Stock.items['Xerox'].append({self.name: self.price}) + Stock.items['Xerox'][0] += 1 + self.location = 'Stock' + + def move(self, where): + self.location = where + Stock.items['Xerox'].remove({self.name: self.price}) + Stock.items['Xerox'][0] -= 1 + + +Epson = Printer('Epson', 23423) +Epson.stock() +Stock.count('Printer') +Epson.move('NPL-11') +Stock.count('Printer') \ No newline at end of file diff --git a/#6.py b/#6.py new file mode 100644 index 0000000..f6f6e1c --- /dev/null +++ b/#6.py @@ -0,0 +1,109 @@ +class OnlyNumber(Exception): + def __init__(self, txt): + self.txt = txt + + +class Stock: + items = {'Printer': [0], 'Scanner': [0], 'Xerox': [0]} + + @staticmethod + def count(type): + print(Stock.items[type][0]) + + +class Equipment(Stock): + pass + + +class Printer(Equipment): + def __init__(self, name, price, quantity=1): + self.price = price + self.name = name + self.quantity = quantity + self.location = None + + def stock(self): + try: + if not isinstance(self.quantity, int): + raise OnlyNumber('Необходимо ввести число!') + else: + Stock.items['Printer'][0] += self.quantity + for i in range(self.quantity): + Stock.items['Printer'].append({self.name: self.price}) + self.location = 'Stock' + except OnlyNumber as err: + print(err) + self.quantity = int(input('Введите количество: ')) + self.stock() + + def move(self, where): + self.location = where + for i in range(self.quantity): + Stock.items['Printer'].remove({self.name: self.price}) + Stock.items['Printer'][0] -= self.quantity + + +class Scanner(Equipment): + def __init__(self, name, price, quantity=1): + self.price = price + self.name = name + self.quantity = quantity + self.location = None + + def stock(self): + try: + if not isinstance(self.quantity, int): + raise OnlyNumber('Необходимо ввести число!') + else: + Stock.items['Scanner'][0] += self.quantity + for i in range(self.quantity): + Stock.items['Scanner'].append({self.name: self.price}) + self.location = 'Stock' + except OnlyNumber as err: + print(err) + self.quantity = int(input('Введите количество: ')) + self.stock() + + def move(self, where): + self.location = where + for i in range(self.quantity): + Stock.items['Scanner'].remove({self.name: self.price}) + Stock.items['Scanner'][0] -= self.quantity + + +class Xerox(Equipment): + counter = 0 + + def __init__(self, name, price, quantity=1): + self.price = price + self.name = name + self.location = None + self.quantity = quantity + + def stock(self): + try: + if not isinstance(self.quantity, int): + raise OnlyNumber('Необходимо ввести число!') + else: + Stock.items['Xerox'][0] += self.quantity + for i in range(self.quantity): + Stock.items['Xerox'].append({self.name: self.price}) + self.location = 'Stock' + except OnlyNumber as err: + print(err) + self.quantity = int(input('Введите количество: ')) + self.stock() + + def move(self, where): + self.location = where + for i in range(self.quantity): + Stock.items['Xerox'].remove({self.name: self.price}) + Stock.items['Xerox'][0] -= self.quantity + + +Epson = Printer('Epson', 23142, '1') +Epson.stock() +Stock.count('Printer') +print(Stock.items) +Epson.move('12') +print(Stock.items) \ No newline at end of file diff --git a/#7.py b/#7.py new file mode 100644 index 0000000..1f0109c --- /dev/null +++ b/#7.py @@ -0,0 +1,20 @@ +class ComplexNumber: + def __init__(self, real_part, imaginary_part): + self.real = real_part + self.imaginary = imaginary_part + + def __str__(self): + return f'{self.real} + {self.imaginary}i' if self.imaginary > 0 else f'{self.real} - {abs(self.imaginary)}i' + + def __add__(self, other): + return ComplexNumber(self.real + other.real, self.imaginary + other.imaginary) + + def __mul__(self, other): + return ComplexNumber(self.real * other.real - self.imaginary * other.imaginary, self.real * other.imaginary + self.imaginary * other.real) + + +number = ComplexNumber(1, -2) +number2 = ComplexNumber(3, 5) +suma = number + number2 +multip = number * number2 +print(suma, multip)