Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init #1812

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

init #1812

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
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions Урок 8. Практическое задание/task_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,40 @@
Второй, с декоратором @staticmethod, должен проводить валидацию числа, месяца
и года (например, месяц — от 1 до 12). Проверить работу полученной структуры на реальных данных.
"""


class OwnDate:
def __init__(self, day_month_year):
self.day_month_year = str(day_month_year)

@classmethod
def extract(cls, day_month_year):
date = []

for i in day_month_year.split():
if i != '-':
date.append(i)

return int(date[0]), int(date[1]), int(date[2])

@staticmethod
def valid(day, month, year):

if day not in range(1, 32):
return f'День указан некорретно'
if month not in range(1, 13):
return f'Месяц укaзан некорретно'
if year not in range(0, 2100):
return f'Год указан некорретно'
return f'Данные укaзаны корректно'

def __str__(self):
return f'Дата на сегодня {OwnDate.extract(self.day_month_year)}'


today = OwnDate('22 - 6 - 2023')
print(today)
print(OwnDate.valid(31, 11, 2022))
print(today.valid(15, 18, 1990))
print(OwnDate.extract('31 - 9 - 2021'))
print(today.extract('22 - 6 - 2023'))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выполнено

19 changes: 19 additions & 0 deletions Урок 8. Практическое задание/task_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,22 @@
Проверьте его работу на данных, вводимых пользователем. При вводе пользователем нуля
в качестве делителя программа должна корректно обработать эту ситуацию и не завершиться с ошибкой.
"""


class MyException(Exception):
txt = "Error"

def __str__(self):
return self.txt


number = int(input('Please enter number '))
devider = int(input('Please enter devider '))

try:
if devider == 0:
raise MyException
except MyException as err:
print(err)
else:
print(f'result of devision is {number / devider:.2f}')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выполнено

24 changes: 24 additions & 0 deletions Урок 8. Практическое задание/task_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,27 @@

Класс-исключение должен контролировать типы данных элементов списка.
"""


class MyException(Exception):
txt = "Error! Value can't be converted to int"

def __str__(self):
return self.txt


final_list = []
while True:
val = input("Please enter number or 'stop' for finish ")
if val == 'stop':
break
else:
try:
if val.isnumeric():
final_list.append(int(val))
else:
raise MyException
except MyException as err:
print(err)

print(final_list)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выполнено

62 changes: 62 additions & 0 deletions Урок 8. Практическое задание/task_4_5_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,65 @@
Подсказка: постарайтесь по возможности реализовать в проекте
«Склад оргтехники» максимум возможностей, изученных на уроках по ООП.
"""


class Warehouse:

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_warehouse_full = []
self.my_warehouse = []
self.my_unit = {'Модель устройства': self.name, 'Цена за ед. товара': self.price, 'Количество': self.quantity}

def __str__(self):
return f'{self.name} цена {self.price} количество {self.quantity}'

def reception(self):
try:
unit = input(f'Ввод модели устройства: ')
price = int(input(f'Ввод цены цены устройства за единицу в рублях: '))
qty = int(input(f'Ввод количества товара: '))
unique = {'Модель устройства': unit, 'Цена за ед.товара': price, 'Количество': qty}
self.my_unit.update(unique)
self.my_warehouse.append(self.my_unit)
print(f'Текущий список: \n {self.my_warehouse}')
except:
return f'Ошибка ввода данных'

print(f'Для выхода ввести ex, для продолжения нажать Enter ')
q = input()
if q == 'ex':
self.my_warehouse_full.append(self.my_warehouse)
print(f'Весь склад: \n {self.my_warehouse_full}')
return f'Выход '
else:
return Warehouse.reception(self)


class Printer(Warehouse):
def to_print(self):
return f'напечатать стр.{self.numb} раз'


class Scanner(Warehouse):
def to_scan(self):
return f'отсканировать лист {self.numb} раз'


class Copier(Warehouse):
def to_copier(self):
return f'копировать лист {self.numb} раз'


unit_1 = Printer('Samsung', 8500, 10, 30)
unit_2 = Scanner('HP', 6550, 7, 25)
unit_3 = Copier('Xerox', 4600, 3, 33)
print(unit_1.reception())
print(unit_2.reception())
print(unit_3.reception())
print(unit_1.to_print())
print(unit_2.to_scan())
print(unit_3.to_copier())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выполнено

21 changes: 21 additions & 0 deletions Урок 8. Практическое задание/task_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,24 @@
создав экземпляры класса (комплексные числа) и выполнив сложение и умножение созданных экземпляров.
Проверьте корректность полученного результата.
"""


class ComplexNumber:
def __init__(self, a, b):
self.a = a
self.b = b

def __add__(self, other):
return f'Сумма: {self.a + other.a} + {self.b + other.b}i'

def __mul__(self, other):
return f'Произведение: {(self.a * other.a) - (self.b * other.b)} {self.b * other.a}i'

def __str__(self):
return f'{self.a}{"+" if self.b > 0 else ""}{self.b}i'


first_numbers = ComplexNumber(8, 6)
second_numbers = ComplexNumber(-98, 7)
print(first_numbers + second_numbers)
print(first_numbers * second_numbers)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выполнено