Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions task_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Data:

def __init__(self, data):
self.data = data

@staticmethod
def valid_data(dd, mm, yy):
if yy < 0:
return False
if mm < 0 or mm > 12:
return False
if dd < 0 or dd > 31:
return False
if mm % 2 == 0:
if mm != 2 and dd > 30:
return False
if mm == 2 and dd > 28:
return False
return True

@classmethod
def pars_data(cls, data):
my_yy = int(data[0:4])
my_mm = int(data[4:6])
my_dd = int(data[6:8])
if cls.valid_data(dd=my_dd, mm=my_mm, yy=my_yy):
print(f"Дата {data} корректна")
else:
print(f"Дата {data} не корректная")


d_1 = Data("20211201")
d_2 = Data("19010228")
d_3 = Data("20003311")

d_1.pars_data(d_1.data)
d_1.pars_data(d_2.data)
d_1.pars_data(d_3.data)

17 changes: 17 additions & 0 deletions task_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Zero(ZeroDivisionError):
def __init__(self, txt):
self.txt = txt


a = int(input("Введите делимое: "))
b = int(input("Введите делитель: "))
result = 0

try:
if b == 0:
raise Zero("Деление на ноль")
result = a / b
print(result)
except Zero as err:
print(err)

24 changes: 24 additions & 0 deletions task_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class DigitError(Exception):

def __init__(self, txt):
self.txt = txt


result_list = []
i = True

while i:
try:
a = input("Введите число, для выхода введите 'stop': ")
if a.isdigit():
result_list.append(a)
else:
raise DigitError("Вы ввели не число")
except DigitError as err:
print(err)
finally:
if a == "stop":
i = False
print(result_list)


80 changes: 80 additions & 0 deletions task_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from abc import ABC, abstractmethod


class Repository:

def __init__(self):
self.rep = {}

def add_technics(self, technics, count):
if self.rep.get(technics.name) is None:
self.rep.update({technics.name: int(count)})
else:
a = int(count) + int(self.rep.get(technics.name))
self.rep.update({technics.name: a})

def del_technics(self, technics, count):
a = self.rep.get(technics)
if a is None:
print(f"Техника {technics.name} на складе не найдена")
elif a - int(count) < 0:
print(f"На складе только {a} едениц техники {technics.name} уточните запрос")
else:
self.rep.update({technics.name: (a - int(count))})


class OfficeEquipment(ABC):

def __init__(self, name):
self.name = name

def turn_on(self):
print(f"{self.name} включен.")

def turn_of(self):
print(f"{self.name} выключен")

@abstractmethod
def work(self):
pass


class Printer(OfficeEquipment):

def __init__(self, name, color):
super().__init__(name)
self.color = color

def work(self):
print("Идет печать")


class Xerox(OfficeEquipment):

def __init__(self, name, model):
super().__init__(name)
self.model = model

def work(self):
print("Копирую")


class Copy(OfficeEquipment):
def __init__(self, name):
super().__init__(name)

def work(self):
pass


r = Repository()
p = Printer("принтер 1", "черный")
p_2 = Printer("принтер 2", "белый")
p_3 = Printer("принтер 3", "синий")
r.add_technics(p, 2)
r.add_technics(p, 4)
r.add_technics(p_2, 3)
r.add_technics(p_3, 4)

print(r.rep)