-
Notifications
You must be signed in to change notification settings - Fork 325
Урок 8 #1796
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
base: master
Are you sure you want to change the base?
Урок 8 #1796
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,22 @@ | |
| Проверьте его работу на данных, вводимых пользователем. При вводе пользователем нуля | ||
| в качестве делителя программа должна корректно обработать эту ситуацию и не завершиться с ошибкой. | ||
| """ | ||
| class Own_error(Exception): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. нарушение пеп-8 в именах классов |
||
| def __init__(self, txt): | ||
| self.txt = txt | ||
|
|
||
| def div_by_null(): | ||
| try: | ||
| div = int(input('Ввод делимого: ')) | ||
| denominator = int(input('Ввод делителя: ')) | ||
| if denominator == 0: | ||
| raise Own_error("На ноль делить нельзя") | ||
| else: | ||
| quotient = div / denominator | ||
| return quotient | ||
| except ValueError: | ||
| return "Введено не число" | ||
| except Own_error as err: | ||
| return err | ||
|
|
||
| print(div_by_null()) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,3 +9,35 @@ | |
|
|
||
| Класс-исключение должен контролировать типы данных элементов списка. | ||
| """ | ||
|
|
||
| def Is_integer(v): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. также имена |
||
| try: | ||
| float(v) | ||
| except ValueError: | ||
| return False | ||
| else: | ||
| return float(v).Is_integer() | ||
|
|
||
|
|
||
| class MyException(Exception): | ||
| def __init__(self, txt): | ||
| self.txt = txt | ||
|
|
||
|
|
||
| int_lst = [] | ||
| while True: | ||
| try: | ||
| input_data = input("Ввести число для cписка (для выходa введите / ) : ") | ||
|
|
||
| if input_data == "/": | ||
| break | ||
|
|
||
| if not Is_integer(input_data): | ||
| raise MyException(input_data) | ||
|
|
||
| int_lst.append(int(input_data)) | ||
| except MyException as err: | ||
| print("Введено не число, повторите попытку") | ||
|
|
||
| print(f"Результат: {int_lst}") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,3 +19,64 @@ | |
| Подсказка: постарайтесь по возможности реализовать в проекте | ||
| «Склад оргтехники» максимум возможностей, изученных на уроках по ООП. | ||
| """ | ||
|
|
||
| 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()) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. выполнено |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. выполнено |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
выполнено