|
@@ -0,0 +1,210 @@
|
|
|
+import math
|
|
|
+
|
|
|
+class Cat:
|
|
|
+
|
|
|
+ breed = 'pers'
|
|
|
+
|
|
|
+ def hello():
|
|
|
+ print("hello")
|
|
|
+
|
|
|
+ def show_breed(instance):
|
|
|
+ print(f'my breed is {instance.breed}')
|
|
|
+ print(instance)
|
|
|
+
|
|
|
+ def show_name(instance):
|
|
|
+ if hasattr(instance, 'name'):
|
|
|
+ print(f'my name is {instance.name}')
|
|
|
+ else:
|
|
|
+ print('nothing')
|
|
|
+
|
|
|
+ def set_value(koshka, value, age=0):
|
|
|
+ koshka.name = value
|
|
|
+ koshka.age = age
|
|
|
+
|
|
|
+ def new_method(self):
|
|
|
+ pass
|
|
|
+
|
|
|
+class Point:
|
|
|
+
|
|
|
+ list_points = []
|
|
|
+
|
|
|
+ def __init__(self, x, y) -> None:
|
|
|
+ self.move_to(x, y)
|
|
|
+ Point.list_points.append(self)
|
|
|
+
|
|
|
+ def move_to(self, x, y):
|
|
|
+ self.x = x
|
|
|
+ self.y = y
|
|
|
+
|
|
|
+ def go_home(self):
|
|
|
+ self.move_to(0, 0)
|
|
|
+
|
|
|
+ def print_point(self):
|
|
|
+ print(f"Точка с координатами ({self.x}, {self.y})")
|
|
|
+
|
|
|
+ def calc_distance(self, another_point):
|
|
|
+ if not isinstance(another_point, Point):
|
|
|
+ raise ValueError("Аргумент должен принадлежать классу Точка")
|
|
|
+ return math.sqrt((self.x - another_point.x)**2 + (self.y -another_point.y)**2)
|
|
|
+
|
|
|
+class Numbers:
|
|
|
+
|
|
|
+ def __init__(self, *args) -> None:
|
|
|
+ self.values = []
|
|
|
+ self.values.extend(args)
|
|
|
+
|
|
|
+ def add_number(self, val):
|
|
|
+ self.values.append(val)
|
|
|
+
|
|
|
+ def get_positive(self):
|
|
|
+ return [x for x in self.values if x > 0]
|
|
|
+
|
|
|
+ def get_negative(self):
|
|
|
+ return [x for x in self.values if x < 0]
|
|
|
+
|
|
|
+ def get_zeroes(self):
|
|
|
+ return [x for x in self.values if x == 0]
|
|
|
+
|
|
|
+
|
|
|
+class Stack:
|
|
|
+ def __init__(self):
|
|
|
+ self.values = []
|
|
|
+
|
|
|
+ def push(self, value):
|
|
|
+ self.values.append(value)
|
|
|
+
|
|
|
+ def pop(self):
|
|
|
+ if not self.values:
|
|
|
+ print("Empty Stack")
|
|
|
+ else:
|
|
|
+ return self.values.pop()
|
|
|
+
|
|
|
+ def peek(self):
|
|
|
+ if not self.values:
|
|
|
+ print("Empty Stack")
|
|
|
+ return None
|
|
|
+ return self.values[-1]
|
|
|
+
|
|
|
+ def is_empty(self):
|
|
|
+ return not bool(self.values)
|
|
|
+
|
|
|
+ def size(self):
|
|
|
+ return len(self.values)
|
|
|
+
|
|
|
+class Worker:
|
|
|
+ def __init__(self, name, salary, gender, passport):
|
|
|
+ self.name = name
|
|
|
+ self.salary = salary
|
|
|
+ self.gender = gender
|
|
|
+ self.passport = passport
|
|
|
+
|
|
|
+ def get_info(self):
|
|
|
+ print(f"Worker {self.name}; passport-{self.passport}")
|
|
|
+
|
|
|
+
|
|
|
+class CustomLabel:
|
|
|
+ def __init__(self, text, **kw):
|
|
|
+ self.text = text
|
|
|
+ for name, value in kw.items():
|
|
|
+ setattr(self, name, value)
|
|
|
+
|
|
|
+ def config(self, **kw):
|
|
|
+ for name, value in kw.items():
|
|
|
+ setattr(self, name, value)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def main():
|
|
|
+
|
|
|
+ """CustomLabel"""
|
|
|
+ label1 = CustomLabel(text="Hello Python", fg="#eee", bg="#333")
|
|
|
+ label2 = CustomLabel(text="Username")
|
|
|
+ label3 = CustomLabel(text="Password", font=("Comic Sans MS", 24, "bold"), bd=20, bg='#ffaaaa')
|
|
|
+ label4 = CustomLabel(text="Hello", bd=20, bg='#ffaaaa')
|
|
|
+ label5 = CustomLabel(text="qwwerty", a=20, b='#ffaaaa', r=[3, 4, 5, 6], p=32)
|
|
|
+
|
|
|
+ assert label1.__dict__ == {'text': 'Hello Python', 'fg': '#eee', 'bg': '#333'}
|
|
|
+ assert label2.__dict__ == {'text': 'Username'}
|
|
|
+ assert label3.__dict__ == {'text': 'Password', 'font': ('Comic Sans MS', 24, 'bold'), 'bd': 20, 'bg': '#ffaaaa'}
|
|
|
+ assert label4.__dict__ == {'text': 'Hello', 'bd': 20, 'bg': '#ffaaaa'}
|
|
|
+ assert label5.__dict__ == {'text': 'qwwerty', 'a': 20, 'b': '#ffaaaa', 'r': [3, 4, 5, 6], 'p': 32}
|
|
|
+
|
|
|
+ print(label1.__dict__)
|
|
|
+ print(label2.__dict__)
|
|
|
+ print(label3.__dict__)
|
|
|
+ print(label4.__dict__)
|
|
|
+ print(label5.__dict__)
|
|
|
+
|
|
|
+ label4.config(color='red', bd=100)
|
|
|
+ label5.config(color='red', bd=100, a=32, b=432, p=100, z=432)
|
|
|
+
|
|
|
+ assert label4.__dict__ == {'text': 'Hello', 'bd': 100, 'bg': '#ffaaaa', 'color': 'red'}
|
|
|
+ assert label5.__dict__ == {'text': 'qwwerty', 'a': 32, 'b': 432, 'r': [3, 4, 5, 6], 'p': 100,
|
|
|
+ 'color': 'red', 'bd': 100, 'z': 432}
|
|
|
+
|
|
|
+ """Class Numbers"""
|
|
|
+ '''
|
|
|
+ num = Numbers(1, 2, -3, -4, 5)
|
|
|
+ num.get_values()
|
|
|
+ print(num.get_positive())
|
|
|
+ '''
|
|
|
+
|
|
|
+ """Class Stack"""
|
|
|
+ # stack = Stack()
|
|
|
+ # stack.peek()
|
|
|
+ # print(stack.is_empty())
|
|
|
+
|
|
|
+ """Worker"""
|
|
|
+ """
|
|
|
+ persons= [
|
|
|
+ ('Allison Hill', 334053, 'M', '1635644202'),
|
|
|
+ ('Megan Mcclain', 191161, 'F', '2101101595'),
|
|
|
+ ('Brandon Hall', 731262, 'M', '6054749119'),
|
|
|
+ ('Michelle Miles', 539898, 'M', '1355368461'),
|
|
|
+ ('Donald Booth', 895667, 'M', '7736670978'),
|
|
|
+ ('Gina Moore', 900581, 'F', '7018476624'),
|
|
|
+ ('James Howard', 460663, 'F', '5461900982'),
|
|
|
+ ('Monica Herrera', 496922, 'M', '2955495768'),
|
|
|
+ ('Sandra Montgomery', 479201, 'M', '5111859731'),
|
|
|
+ ('Amber Perez', 403445, 'M', '0602870126')
|
|
|
+ ]
|
|
|
+
|
|
|
+
|
|
|
+ # workers_objects = [Worker('Bob Moore', 330000, 'M', '1635777202')]
|
|
|
+
|
|
|
+ workers_objects = [Worker(*x) for x in persons]
|
|
|
+
|
|
|
+ for worker in workers_objects:
|
|
|
+ worker.get_info()
|
|
|
+ """
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ # print(persons[0][1])
|
|
|
+
|
|
|
+ # for person in persons:
|
|
|
+ # workers_objects.append('')
|
|
|
+
|
|
|
+ # cat = Cat()
|
|
|
+ # cat.show_breed()
|
|
|
+
|
|
|
+ # tom = Cat()
|
|
|
+ # print(isinstance(tom, Cat))
|
|
|
+
|
|
|
+ # tom.show_name()
|
|
|
+ # tom.set_value('Tom')
|
|
|
+ # tom.show_name()
|
|
|
+
|
|
|
+ # leo.score(700)
|
|
|
+ # assert leo.goals == 700
|
|
|
+ # leo.make_assist(500)
|
|
|
+ # assert leo.assists == 500
|
|
|
+
|
|
|
+ # leo.statistics()
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ main()
|