-
Notifications
You must be signed in to change notification settings - Fork 337
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
Lesson8 #1809
base: master
Are you sure you want to change the base?
Lesson8 #1809
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,20 @@ | |
Проверьте его работу на данных, вводимых пользователем. При вводе пользователем нуля | ||
в качестве делителя программа должна корректно обработать эту ситуацию и не завершиться с ошибкой. | ||
""" | ||
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)) | ||
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 |
---|---|---|
|
@@ -9,3 +9,33 @@ | |
|
||
Класс-исключение должен контролировать типы данных элементов списка. | ||
""" | ||
|
||
|
||
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()) | ||
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 |
---|---|---|
|
@@ -19,3 +19,66 @@ | |
Подсказка: постарайтесь по возможности реализовать в проекте | ||
«Склад оргтехники» максимум возможностей, изученных на уроках по ООП. | ||
""" | ||
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()) | ||
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,26 @@ | |
создав экземпляры класса (комплексные числа) и выполнив сложение и умножение созданных экземпляров. | ||
Проверьте корректность полученного результата. | ||
""" | ||
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) | ||
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 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.
выполнено