Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class Point:
def __init__(self, x, y):
self.x = x
self.y = y

def __str__(self):
return "x = {}, y = {}".format(self.x, self.y)


class Circle:
def __init__(self, center, radius):
self.center = center
self.radius = radius


class Rectangle:
def __init__(self, width, height, corner):
self.width = width
self.height = height
self.corner = corner


def point_in_circle(point, circle):
if (point.x - circle.center.x) * (point.x - circle.center.x) + (point.y - circle.center.y) * (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E501 line too long (98 > 79 characters)

point.y - circle.center.y) <= circle.radius * circle.radius:
return True
else:
return False


def rectangle_points(rect):
left_down = rect.corner
left_up = Point(left_down.x, left_down.y + rect.height)
right_down = Point(left_down.x + rect.width, left_down.y)
right_up = Point(left_down.x + rect.width, left_down.y + rect.height)
result = [left_down, left_up, right_up, right_down]
return result


def rect_in_circle(rectangle, circle):
points = rectangle_points(rectangle)
for point in points:
if not point_in_circle(point, circle):
return False
else:
return True


def rect_circle_overlap(rectangle, circle):
points = rectangle_points(rectangle)
for point in points:
if point_in_circle(point, circle):
return True
else:
return False


def main():
circle = Circle(Point(150, 100), 75)
point = Point(50, 100)
rectangle = Rectangle(20, 10, Point(120, 100))
print("Point:" + str(point))
print("Is point inside the circle? " + str(point_in_circle(point, circle)))
print("Is rectangle inside the circle? " + str(rect_in_circle(rectangle, circle)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E501 line too long (86 > 79 characters)

print("Is rectangle overlapping the circle? " + str(rect_circle_overlap(rectangle, circle)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E501 line too long (96 > 79 characters)



if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Books:
def __init__(self, title, author, year):
self.title = title
self.author = author
self.year = year


# def __dir__(self):
# return [self.author, self.title, self.year]


def object_inspector1(some_object):
attributes = dir(some_object)
return dict((key, getattr(some_object, key)) for key in attributes)


def object_inspector2(some_object):
attributes = dir(some_object)
return dict((key, getattr(some_object, key)) for key in attributes
if isinstance(getattr(some_object, key), (int, float, str)))


def main():
ksiazka = Books("Hasztag", "Remigiusz Mroz", 2018)
print(object_inspector1(ksiazka))
print(object_inspector2(ksiazka))


if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Books:
def __init__(self, title, author, year):
self.title = title
self.author = author
self.year = year


def shallow_compare(object1, object2, attributes):
for attribute in attributes:
if getattr(object1, attribute) != getattr(object2, attribute):
return False
else:
return True


def main():
book1 = Books("Uwiklanie", "Zygmunt Miloszewski", 2007)
book2 = Books("Uwiklanie", "Zygmunt Miloszewski", 2007)
book3 = Books("Hasztag", "Remigiusz Mroz", 2018)
print("Book1: author: {}, title: {}, year: {}".format(book1.author, book1.title, book1.year))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E501 line too long (97 > 79 characters)

print("Book2: author: {}, title: {}, year: {}".format(book2.author, book2.title, book2.year))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E501 line too long (97 > 79 characters)

print("Book3: author: {}, title: {}, year: {}".format(book3.author, book3.title, book3.year))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E501 line too long (97 > 79 characters)

attributes_list = ['title', 'author', 'year']
print("Are book 1 and book 2 equal? " + str(shallow_compare(book1, book2, attributes_list)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E501 line too long (96 > 79 characters)

print("Are book 1 and book 3 equal? " + str(shallow_compare(book1, book3, attributes_list)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E501 line too long (96 > 79 characters)



if __name__ == "__main__":
main()