# Python OOP with Dynamic Typing

Online tutoring services

Need help with this question or any other Computer Science assignment help task? Click on the button below to to hire an expert cheap.

I need help with this short Python homework about shapes, link to the assignment page is here https://sites.google.com/cs.stonybrook.edu/cse-216/assignments_1/assignment-5-oop-with-dynamic-typing

You can download the code on the page or you can also see the attached files below.

Some clarifications- in order to check equality of shapes for each class, you want them to have the same type and same coordinates. For the TwoDPoint Class,where the TODO magic method is, p is self and q is other, and adding/subtracting would mean x1-x2 and so on.

## Get Help With a similar task to - Python OOP with Dynamic Typing

hw5codebase/quadrilateral.py from .two_d_point import TwoDPoint from typing import Tuple class Quadrilateral: def __init__(self, *floats): points = TwoDPoint.from_coordinates(list(floats)) self.__vertices = tuple(points[0:3]) @property def vertices(self): return self.__vertices def side_lengths(self): """Returns a tuple of four floats, each denoting the length of a side of this quadrilateral. The value must be ordered clockwise, starting from the top left corner.""" return 0, 0, 0, 0 # TODO def smallest_x(self): """Returns the x-coordinate of the vertex with the smallest x-value of the four vertices of this quadrilateral.""" return 0 # TODO hw5codebase/rectangle.py from .quadrilateral import Quadrilateral from .two_d_point import TwoDPoint class Rectangle(Quadrilateral): def __init__(self, *floats): super().__init__(*floats) if not self.__is_member(): raise TypeError("A rectangle cannot be formed by the given coordinates.") def __is_member(self): """Returns True if the given coordinates form a valid rectangle, and False otherwise.""" return False # TODO def center(self): """Returns the center of this rectangle, calculated to be the point of intersection of its diagonals.""" return TwoDPoint(0, 0) # TODO def area(self): """Returns the area of this rectangle. The implementation invokes the side_lengths() method from the superclass, and computes the product of this rectangle's length and width.""" return 0 # TODO hw5codebase/square.py from .rectangle import Rectangle from .quadrilateral import Quadrilateral class Square(Rectangle): def __init__(self, *floats): super().__init__(*floats) if not self.__is_member(): raise TypeError("A square cannot be formed by the given coordinates.") def snap(self): """Snaps the sides of the square such that each corner (x,y) is modified to be a corner (x',y') where x' is the integer value closest to x and y' is the integer value closest to y. This, of course, may change the shape to a general quadrilateral, hence the return type. The only exception is when the square is positioned in a way where this approximation will lead it to vanish into a single point. In that case, a call to snap() will not modify this square in any way.""" return Quadrilateral() # TODO hw5codebase/two_d_point.py from typing import List class TwoDPoint: def __init__(self, x, y) -> None: self.__x = x self.__y = y @property def x(self): return self.__x @property def y(self): return self.__y def __eq__(self, other: object) -> bool: return False # TODO def __ne__(self, other: object) -> bool: return not self.__eq__(other) def __str__(self) -> str: return '(%g, %g)' % (self.__x, self.__y) # TODO: add magic methods such that two TwoDPoint objects can be added and subtracted coordinate-wise just by using # syntax of the form p + q or p - q @staticmethod def from_coordinates(coordinates: List[float]): if len(coordinates) % 2 != 0: raise Exception("Odd number of floats given to build a list of 2-d points") points = [] it = iter(coordinates) for x in it: points.append(TwoDPoint(x, next(it))) return points

## Related Questions

Similar orders to Python OOP with Dynamic Typing
4
Views
0
Practical Project, reading files and creating an output array
https://www.cs.colostate.edu/~cs163/.Fall21/practicals/p3/ The link will take you to the instructions, all files needed are attached there with instructions on methods, variables, etc...
17
Views
0
Modeling a Relational Database in MySQL
You will need to submit the entity relationship data model in MWB format with a screenshot either in JPG or PNG format, after adding at least three records to each table. The logical model should include the tables, attributes, keys, mandatory role constraints, and referential integrity constraints. I will also need the output script in SQL format or text-based file after forward engineering the designed ER-model....
44
Views
0 