Skip to content

Commit 25b4c16

Browse files
authored
Add files via upload
1 parent 0bbf7d8 commit 25b4c16

5 files changed

Lines changed: 291 additions & 0 deletions

File tree

1.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class Date():
2+
def __init__(self, inner_date):
3+
print('innit metod is work')
4+
self.date = inner_date
5+
6+
@classmethod
7+
def func_class_extract(cls, date):
8+
print('class metod is work')
9+
return list(int(i) for i in date.split('-'))
10+
11+
@staticmethod
12+
def func_validator(inner):
13+
print('static metod is work')
14+
if 0 < inner[0] < 31:
15+
print(f'day {inner[0]} ok')
16+
else:
17+
print(f'error day {inner[0]}')
18+
if 0 < inner[1] < 13:
19+
print(f'month {inner[1]} ok')
20+
else:
21+
print(f'error month {inner[0]}')
22+
if 2000 < inner[2] < 2022:
23+
print(f'year {inner[1]} ok and period 2000-2022')
24+
else:
25+
print(f'error year {inner[0]}')
26+
27+
28+
Date('12-10-2021') # innit metod is work
29+
30+
res = Date.func_class_extract('12-10-2021') # class metod is work
31+
print(res)
32+
33+
Date.func_validator(res) # static metod is work

2.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
3+
class ZeroDiv(ZeroDivisionError):
4+
def __init__(self, *args):
5+
if args:
6+
self.message = args[0]
7+
else:
8+
self.message = None
9+
10+
def __str__(self):
11+
print('calling str')
12+
if self.message:
13+
return f'my zero division {self.message}'
14+
else:
15+
return f'my zero division'
16+
17+
# raise ZeroDiv
18+
19+
# one_in = int(input('введите значение делимого '))
20+
def test_func():
21+
one_value = 5
22+
two_value = 0
23+
24+
try:
25+
one = float(one_value)
26+
two = float(two_value)
27+
res = one/two
28+
except ValueError:
29+
print(f'некорректно введено значение')
30+
except ZeroDivisionError as e:
31+
print('перехват базового ZeroDivisionError')
32+
raise ZeroDiv('test_zero_div')
33+
34+
35+
if __name__ == '__main__':
36+
try:
37+
test_func()
38+
except ZeroDiv:
39+
print('перехват моего ZeroDiv')
40+
print('ok')

3.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class My_exeption(ValueError):
2+
def __init__(self, *argv):
3+
self.message = argv[0]
4+
5+
def __str__(self):
6+
return f'my error {self.message}'
7+
8+
def check_digit(self, li):
9+
for num in li:
10+
try:
11+
print(f'{type(num)} num ')
12+
z = float(num)
13+
except ValueError:
14+
raise My_exeption
15+
16+
li = []
17+
while True:
18+
in_value = input('введите значение для добавлени в список (q - для выхода) ')
19+
if in_value == 'stop':
20+
break
21+
try:
22+
try:
23+
val = float(in_value)
24+
except ValueError:
25+
raise My_exeption('введено некорректное значение')
26+
except My_exeption as e:
27+
print(f'my extption {e}')
28+
else:
29+
li.append(val)
30+
31+
print(f' result list {li}')

4_5_6.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
from abc import abstractmethod
2+
3+
4+
class Store():
5+
def __init__(self):
6+
self.full_dict = {}
7+
8+
def get_unit(self, unit, name):
9+
unit.set_id(name)
10+
self.full_dict[name] = unit
11+
12+
13+
def move_to_office(self, id):
14+
get_unit = self.full_dict.get(id)
15+
if get_unit:
16+
res = self.full_dict.pop(id)
17+
print(f'{res} move to office')
18+
return res
19+
else:
20+
print(f'NOT in store {id}')
21+
return None
22+
23+
24+
def check_store(self):
25+
print(f'all in store {len(self.full_dict)} units')
26+
if len(self.full_dict):
27+
print(f'this units is:')
28+
for name, cls in self.full_dict.items():
29+
print(name, cls)
30+
31+
32+
33+
class Office_equipment():
34+
@abstractmethod
35+
def __init__(self, in_name, in_type):
36+
self.name = in_name
37+
self.type_is = in_type
38+
39+
def __str__(self):
40+
return f'{self.name} {self.type_is}'
41+
42+
def to_print(self):
43+
print('need define')
44+
45+
def get_name(self):
46+
print(f'{self.name} - {self.type_is}')
47+
48+
49+
class Printer(Office_equipment):
50+
def __init__(self, name, type_is):
51+
super().__init__(name, type_is)
52+
53+
@abstractmethod
54+
def to_do(self):
55+
print(f'{self.name} print pages')
56+
57+
def __str__(self):
58+
return f'{self.name} {self.type_is}'
59+
60+
61+
class Scaner(Office_equipment):
62+
def __init__(self, name, type_is):
63+
super().__init__(name, type_is)
64+
65+
def to_scan(self):
66+
print(f'{self.name} scan to pages')
67+
68+
69+
class MFU(Scaner, Printer):
70+
def __init__(self, name, type_is):
71+
Scaner.__init__(self, name, type_is)
72+
Printer.__init__(self, name, type_is)
73+
# self.id = prop
74+
75+
def to_do(self):
76+
Scaner.to_scan(self)
77+
Printer.to_print(self)
78+
79+
def get_inheritance(self):
80+
print(f'full inheritance clases:\n {MFU.__mro__}')
81+
82+
@classmethod
83+
def get_info_class(cls):
84+
print(cls)
85+
86+
@abstractmethod
87+
def check_info_mfu(cls):
88+
print(cls.__mro__)
89+
print(cls.__module__)
90+
print(cls.__dict__)
91+
92+
@property
93+
def get_id(self):
94+
print(f'{self.name} have id {self.id}')
95+
96+
def set_id(self, in_id):
97+
self.id = in_id
98+
99+
100+
st = Store() # создаем склад
101+
st.check_store() # проверяем склад
102+
103+
mfu = MFU('Xerox', 'R320') # у нас есть МФУ
104+
MFU.get_info_class() # проверяем класс
105+
MFU.check_info_mfu(MFU) # наследование, название модуля, информация о классе
106+
107+
st.get_unit(mfu, '1555') # добавляем мфу на склад присваивая id идентификационный номер
108+
st.check_store()
109+
110+
mfu = st.move_to_office('1555') # склад передает МФУ в офис
111+
112+
mfu.to_do() # тестируем МФУ это принтер и сканер одновременно
113+
mfu.get_name()
114+
mfu.to_scan() # проверяем только сканирование
115+
mfu.get_inheritance() # проверяем наследование
116+
print(mfu.get_id) # проверяем id
117+
118+
119+
120+
mfu = st.move_to_office('1555') # пытаемся получить со склада такой-же МФУ

7.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
class Complex_digit():
2+
def __init__(self, in_digit):
3+
self.digit = in_digit
4+
5+
def check_negativ(self, digit):
6+
return -int(digit) if digit.startswith('-') else int(digit)
7+
8+
def preparation(self, digit):
9+
digit = digit.replace('i', '')
10+
if digit.startswith('-'):
11+
digit = digit[1:]
12+
if '-' in digit:
13+
a, b = digit.split('-')
14+
return -int(a), -int(b)
15+
else:
16+
a, b = digit.split('+')
17+
return -int(a), int(b)
18+
else:
19+
if '-' in digit:
20+
a, b = digit.split('-')
21+
return int(a), -int(b)
22+
else:
23+
a, b = digit.split('+')
24+
return int(a), int(b)
25+
26+
def un_preparation(self, tup):
27+
mark = '+' if tup[1] > 0 else ''
28+
return f'{tup[0]}{mark}{tup[1]}i'
29+
30+
def __add__(self, two):
31+
a, b = self.preparation(self.digit)
32+
c, d = self.preparation(two.digit)
33+
34+
aa = a+c
35+
bb = b+d
36+
37+
res = self.un_preparation((aa, bb))
38+
print(res)
39+
return Complex_digit(res)
40+
41+
def __mul__(self, two):
42+
a, b = self.preparation(self.digit)
43+
c, d = self.preparation(two.digit)
44+
45+
aa = a*c-b*d
46+
bb = a*d+b*c
47+
48+
res = self.un_preparation((aa, bb))
49+
print(res)
50+
return Complex_digit(res)
51+
52+
#
53+
a = Complex_digit('5-6i')
54+
b = Complex_digit('-3+2i')
55+
c = a + b
56+
# print(c)
57+
a = Complex_digit('1+3i')
58+
b = Complex_digit('4-2i')
59+
c = a * b
60+
# print(c)
61+
a = Complex_digit('3-2i')
62+
b = Complex_digit('4+1i')
63+
c = a * b
64+
print(c)
65+
66+
67+
import cmath # для работы с комплексными числами

0 commit comments

Comments
 (0)