Skip to content
Open
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
26 changes: 26 additions & 0 deletions #1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Data:
data = ''

def __init__(self, date):
Data.data = date

@staticmethod
def numbers(date):
n = {}
for i, v in enumerate(date.split('.')):
n[i] = v
return f'день {n[0]} из 31, месяц {n[1]} из 12' if int(n[0]) < 31 and int(n[1]) < 13 else None

@classmethod
def ints(cls):
fn = {}
for m, k in enumerate(cls.data.split('.')):
fn[m] = k
return fn[0], fn[1], fn[2]

def my_method1(self):
return (Data.numbers(Data.data), Data.ints()) if Data.numbers(Data.data) else 'Дата введена неверно'


d = Data('12.03.98')
print(d.my_method1())
15 changes: 15 additions & 0 deletions #2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class ZeroDivision(Exception):
def __init__(self):
self.txt = 'На ноль делить нелязя!'


a = int(input())
b = int(input())
try:
if b == 0:
raise ZeroDivision
except ZeroDivision as err:
print(err)
else:
print(a / b)

19 changes: 19 additions & 0 deletions #3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class OnlyNumber(Exception):
def __init__(self, txt):
self.txt = txt


x = input()
a = []
while x != 'stop':
try:
if not x.isnumeric():
raise OnlyNumber('Необходимо ввести число!')
else:
a.append(int(x))
except OnlyNumber as err:
print(err)
x = input()
print(a)


36 changes: 36 additions & 0 deletions #4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Stock:
pass


class Equipment(Stock):
all_equipment = 0


class Printer(Equipment):
counter = 0

def __init__(self, id, price):
Equipment.all_equipment += 1
Printer.counter += 1
self.price = price
self.id = id


class Scanner(Equipment):
counter = 0

def __init__(self, id, price):
Equipment.all_equipment += 1
Scanner.counter += 1
self.price = price
self.id = id


class Xerox(Equipment):
counter = 0

def __init__(self, id, price):
Equipment.all_equipment += 1
Xerox.counter += 1
self.price = price
self.id = id
80 changes: 80 additions & 0 deletions #5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
class Stock:
items = {'Printer': [0], 'Scanner': [0], 'Xerox': [0]}

@staticmethod
def count(type):
print(Stock.items[type][0])


class Equipment(Stock):
all_equipment = 0


class Printer(Equipment):
counter = 0

def __init__(self, name, price):
Equipment.all_equipment += 1
Printer.counter += 1
self.price = price
self.name = name
self.location = None

def stock(self):
Stock.items['Printer'].append({self.name: self.price})
Stock.items['Printer'][0] += 1
self.location = 'Stock'

def move(self, where):
self.location = where
Stock.items['Printer'].remove({self.name: self.price})
Stock.items['Printer'][0] -= 1


class Scanner(Equipment):
counter = 0

def __init__(self, name, price):
Equipment.all_equipment += 1
Scanner.counter += 1
self.price = price
self.name = name
self.location = None

def stock(self):
Stock.items['Scanner'].append({self.name: self.price})
Stock.items['Scanner'][0] += 1
self.location = 'Stock'

def move(self, where):
self.location = where
Stock.items['Scanner'].remove({self.name: self.price})
Stock.items['Scanner'][0] -= 1


class Xerox(Equipment):
counter = 0

def __init__(self, name, price):
Equipment.all_equipment += 1
Xerox.counter += 1
self.price = price
self.name = name
self.location = None

def stock(self):
Stock.items['Xerox'].append({self.name: self.price})
Stock.items['Xerox'][0] += 1
self.location = 'Stock'

def move(self, where):
self.location = where
Stock.items['Xerox'].remove({self.name: self.price})
Stock.items['Xerox'][0] -= 1


Epson = Printer('Epson', 23423)
Epson.stock()
Stock.count('Printer')
Epson.move('NPL-11')
Stock.count('Printer')
109 changes: 109 additions & 0 deletions #6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
class OnlyNumber(Exception):
def __init__(self, txt):
self.txt = txt


class Stock:
items = {'Printer': [0], 'Scanner': [0], 'Xerox': [0]}

@staticmethod
def count(type):
print(Stock.items[type][0])


class Equipment(Stock):
pass


class Printer(Equipment):
def __init__(self, name, price, quantity=1):
self.price = price
self.name = name
self.quantity = quantity
self.location = None

def stock(self):
try:
if not isinstance(self.quantity, int):
raise OnlyNumber('Необходимо ввести число!')
else:
Stock.items['Printer'][0] += self.quantity
for i in range(self.quantity):
Stock.items['Printer'].append({self.name: self.price})
self.location = 'Stock'
except OnlyNumber as err:
print(err)
self.quantity = int(input('Введите количество: '))
self.stock()

def move(self, where):
self.location = where
for i in range(self.quantity):
Stock.items['Printer'].remove({self.name: self.price})
Stock.items['Printer'][0] -= self.quantity


class Scanner(Equipment):
def __init__(self, name, price, quantity=1):
self.price = price
self.name = name
self.quantity = quantity
self.location = None

def stock(self):
try:
if not isinstance(self.quantity, int):
raise OnlyNumber('Необходимо ввести число!')
else:
Stock.items['Scanner'][0] += self.quantity
for i in range(self.quantity):
Stock.items['Scanner'].append({self.name: self.price})
self.location = 'Stock'
except OnlyNumber as err:
print(err)
self.quantity = int(input('Введите количество: '))
self.stock()

def move(self, where):
self.location = where
for i in range(self.quantity):
Stock.items['Scanner'].remove({self.name: self.price})
Stock.items['Scanner'][0] -= self.quantity


class Xerox(Equipment):
counter = 0

def __init__(self, name, price, quantity=1):
self.price = price
self.name = name
self.location = None
self.quantity = quantity

def stock(self):
try:
if not isinstance(self.quantity, int):
raise OnlyNumber('Необходимо ввести число!')
else:
Stock.items['Xerox'][0] += self.quantity
for i in range(self.quantity):
Stock.items['Xerox'].append({self.name: self.price})
self.location = 'Stock'
except OnlyNumber as err:
print(err)
self.quantity = int(input('Введите количество: '))
self.stock()

def move(self, where):
self.location = where
for i in range(self.quantity):
Stock.items['Xerox'].remove({self.name: self.price})
Stock.items['Xerox'][0] -= self.quantity


Epson = Printer('Epson', 23142, '1')
Epson.stock()
Stock.count('Printer')
print(Stock.items)
Epson.move('12')
print(Stock.items)
20 changes: 20 additions & 0 deletions #7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ComplexNumber:
def __init__(self, real_part, imaginary_part):
self.real = real_part
self.imaginary = imaginary_part

def __str__(self):
return f'{self.real} + {self.imaginary}i' if self.imaginary > 0 else f'{self.real} - {abs(self.imaginary)}i'

def __add__(self, other):
return ComplexNumber(self.real + other.real, self.imaginary + other.imaginary)

def __mul__(self, other):
return ComplexNumber(self.real * other.real - self.imaginary * other.imaginary, self.real * other.imaginary + self.imaginary * other.real)


number = ComplexNumber(1, -2)
number2 = ComplexNumber(3, 5)
suma = number + number2
multip = number * number2
print(suma, multip)