-
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
init #1812
base: master
Are you sure you want to change the base?
init #1812
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}') | ||
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,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) | ||
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,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()) | ||
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) | ||
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.
выполнено