-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
187 lines (144 loc) · 5.56 KB
/
main.py
File metadata and controls
187 lines (144 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# 1 задание
class Data:
def __init__(self, day_month_year):
# self.day = day
# self.month = month
# self.year = year
self.day_month_year = str(day_month_year)
@classmethod
def extract(cls, day_month_year):
my_date = []
for i in day_month_year.split():
if i != '-': my_date.append(i)
return int(my_date[0]), int(my_date[1]), int(my_date[2])
@staticmethod
def valid(day, month, year):
if 1 <= day <= 31:
if 1 <= month <= 12:
if 2019 >= year >= 0:
return f'All right'
else:
return f'Неправильный год'
else:
return f'Неправильный месяц'
else:
return f'Неправильный день'
def __str__(self):
return f'Текущая дата {Data.extract(self.day_month_year)}'
today = Data('11 - 1 - 2001')
print(today)
print(Data.valid(11, 11, 2022))
print(today.valid(11, 13, 2011))
print(Data.extract('11 - 11 - 2011'))
print(today.extract('11 - 11 - 2020'))
print(Data.valid(1, 11, 2000))
# 2 задание
class DivisionByNull:
def __init__(self, divider, denominator):
self.divider = divider
self.denominator = denominator
@staticmethod
def divide_by_null(divider, denominator):
try:
return (divider / denominator)
except:
return (f"Деление на ноль недопустимо")
div = DivisionByNull(10, 100)
print(DivisionByNull.divide_by_null(10, 0))
print(DivisionByNull.divide_by_null(10, 0.1))
print(div.divide_by_null(100, 0))
# 3 задание
class Error:
def __init__(self, *args):
self.my_list = []
def my_input(self):
# self.my_list = [int(i) for i in input('Введите значения через пробел ').split()]
# val = int(input('Введите значения и нажимайте Enter - '))
# self.my_list.append(val)
while True:
try:
val = int(input('Введите значения и нажимайте Enter - '))
self.my_list.append(val)
print(f'Текущий список - {self.my_list} \n ')
except:
print(f"Недопустимое значение - строка и булево")
y_or_n = input(f'Попробовать еще раз? Y/N ')
if y_or_n == 'Y' or y_or_n == 'y':
print(try_except.my_input())
elif y_or_n == 'N' or y_or_n == 'n':
return f'Вы вышли'
else:
return f'Вы вышли'
try_except = Error(1)
print(try_except.my_input())
# 4 - 6 задание
class StoreMashines:
def __init__(self, name, price, quantity, number_of_lists, *args):
self.name = name
self.price = price
self.quantity = quantity
self.numb = number_of_lists
self.my_store_full = []
self.my_store = []
self.my_unit = {'Модель устройства': self.name, 'Цена за ед': self.price, 'Количество': self.quantity}
def __str__(self):
return f'{self.name} цена {self.price} количество {self.quantity}'
# @classmethod
# @staticmethod
def reception(self):
# print(f'Для выхода - Q, продолжение - Enter')
# while True:
try:
unit = input(f'Введите наименование ')
unit_p = int(input(f'Введите цену за ед '))
unit_q = int(input(f'Введите количество '))
unique = {'Модель устройства': unit, 'Цена за ед': unit_p, 'Количество': unit_q}
self.my_unit.update(unique)
self.my_store.append(self.my_unit)
print(f'Текущий список -\n {self.my_store}')
except:
return f'Ошибка ввода данных'
print(f'Для выхода - Q, продолжение - Enter')
q = input(f'---> ')
if q == 'Q' or q == 'q':
self.my_store_full.append(self.my_store)
print(f'Весь склад -\n {self.my_store_full}')
return f'Выход'
else:
return StoreMashines.reception(self)
class Printer(StoreMashines):
def to_print(self):
return f'to print smth {self.numb} times'
class Scanner(StoreMashines):
def to_scan(self):
return f'to scan smth {self.numb} times'
class Copier(StoreMashines):
def to_copier(self):
return f'to copier smth {self.numb} times'
unit_1 = Printer('hp', 2000, 5, 10)
unit_2 = Scanner('Canon', 1200, 5, 10)
unit_3 = Copier('Xerox', 1500, 1, 15)
print(unit_1.reception())
print(unit_2.reception())
print(unit_3.reception())
print(unit_1.to_print())
print(unit_3.to_copier())
# 7 задание
class ComplexNumber:
def __init__(self, a, b, *args):
self.a = a
self.b = b
self.z = 'a + b * i'
def __add__(self, other):
print(f'Сумма z1 и z2 равна')
return f'z = {self.a + other.a} + {self.b + other.b} * i'
def __mul__(self, other):
print(f'Произведение z1 и z2 равно')
return f'z = {self.a * other.a - (self.b * other.b)} + {self.b * other.a} * i'
def __str__(self):
return f'z = {self.a} + {self.b} * i'
z_1 = ComplexNumber(1, -2)
z_2 = ComplexNumber(3, 4)
print(z_1)
print(z_1 + z_2)
print(z_1 * z_2)