diff --git a/students/Hebdowska_Grazyna/lesson_13/Selective_shallow_compare .py b/students/Hebdowska_Grazyna/lesson_13/Selective_shallow_compare .py new file mode 100644 index 000000000..e2cd08255 --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_13/Selective_shallow_compare .py @@ -0,0 +1,28 @@ +class Car: + + def __init__(self, name, colour, age): + self.name = name + self.colour = colour + self.age = age + + +def compare(object1, object2, atribute_names): + object1_atr = [] + object2_atr = [] + for i in atribute_names: + object1_atr.append(getattr(object1, i)) + object2_atr.append(getattr(object2, i)) + if object1_atr == object2_atr: + print("Atributes are equal") + else: + print("Atributes are not equal") + + +def main(): + auto1 = Car("fiat", "white", 2) + auto2 = Car("fiat", "red", 2) + compare(auto1, auto2, ["age", "colour"]) + + +if __name__ == '__main__': + main() diff --git a/students/Hebdowska_Grazyna/lesson_13/circle.py b/students/Hebdowska_Grazyna/lesson_13/circle.py new file mode 100644 index 000000000..3de49338f --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_13/circle.py @@ -0,0 +1,109 @@ +import math + + +class Point: + + def __init__(self, x, y): + self.x = x + self.y = y + + +class Circle: + + def __init__(self, center, radius): + self.center = center + self.radius = radius + + +class Rectangle: + + def __init__(self, one_corner, height, width): + self.one_corner = one_corner + self.height = height + self.width = width + + +def distance(point1, point2): + return math.sqrt((point1.x - point2.x) ** 2 + (point1.y - point2.y) ** 2) + + +def point_in_circle(circle, point): + if distance(circle.center, point) <= circle.radius: + return True + else: + return False + + +def corner_point(rectangle): + secound = Point + third = Point + fourth = Point + secound.x = rectangle.one_corner.x + secound.y = rectangle.one_corner.y + rectangle.height + third.x = rectangle.one_corner.x + rectangle.width + third.y = secound.y + fourth.x = third.x + fourth.y = rectangle.one_corner.y + return secound, third, fourth + + +def rect_in_circle(circle, rectangle): + p1 = rectangle.one_corner + p2, p3, p4 = corner_point(rectangle) + if distance(circle.center, p1) > circle.radius: + return False + elif distance(circle.center, p2) > circle.radius: + return False + elif distance(circle.center, p3) > circle.radius: + return False + elif distance(circle.center, p4) > circle.radius: + return False + else: + return True + + +def rect_circle_overlap(cicle, rectangle): + p1 = rectangle.one_corner + p2, p3, p4 = corner_point(rectangle) + if distance(cicle.center, p1) < cicle.radius: + return True + elif distance(cicle.center, p2) < cicle.radius: + return True + elif distance(cicle.center, p3) < cicle.radius: + return True + elif distance(cicle.center, p4) < cicle.radius: + return True + else: + return False + + +def main(): + circle_center = Point(150, 100) + circle = Circle(circle_center, 75) + one_corner = Point(1, 50) + rectangle = Rectangle(one_corner, 20, 50) + point = Point(9, 120) + if point_in_circle(circle, point): + print("the Point lies in" + " or on the boundary of the circle.") + else: + print("the Point doesn't lay" + " in or on the boundary of the circle.") + + if rect_in_circle(circle, rectangle): + print("the Rectangle lies entirely" + " in or on the boundary of the circle.") + else: + print("the Rectangle doesn't lay entirely" + " in or on the boundary of the circle.") + + if rect_circle_overlap(circle, rectangle): + print("some of the corners" + " of the Rectangle fall inside the circle") + else: + print("the corners of the Rectangle" + " are outside the circle") + + +if __name__ == '__main__': + main() diff --git a/students/Hebdowska_Grazyna/lesson_13/object_inspector_1.py b/students/Hebdowska_Grazyna/lesson_13/object_inspector_1.py new file mode 100644 index 000000000..f524849f0 --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_13/object_inspector_1.py @@ -0,0 +1,21 @@ +class Car: + + def __init__(self, name, colour, age): + self.name = name + self.colour = colour + self.age = age + + +def create_dictionary(object): + new_dictionary = object.__dict__ + for i in new_dictionary.keys(): + print("key=", i, "value=", new_dictionary[i]) + + +def main(): + auto = Car("fiat", "white", 2) + create_dictionary(auto) + + +if __name__ == '__main__': + main() diff --git a/students/Hebdowska_Grazyna/lesson_13/object_inspector_2.py b/students/Hebdowska_Grazyna/lesson_13/object_inspector_2.py new file mode 100644 index 000000000..8b8d355b8 --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_13/object_inspector_2.py @@ -0,0 +1,25 @@ +class Car: + def __init__(self, name, colour, age): + self.name = name + self.colour = colour + self.age = age + + +def create_dictionary(object): + new_dictionary = object.__dict__ + for i in new_dictionary.keys(): + if isinstance(new_dictionary[i], int): + print("key=", i, "value=", new_dictionary[i]) + elif isinstance(new_dictionary[i], float): + print("key=", i, "value=", new_dictionary[i]) + elif isinstance(new_dictionary[i], str): + print("key=", i, "value=", new_dictionary[i]) + + +def main(): + auto = Car("fiat", "white", 2) + create_dictionary(auto) + + +if __name__ == '__main__': + main()