辅导CS-UY 1114、 写作python编程语言

” 辅导CS-UY 1114、 写作python编程语言Homework A:ClassesCS-UY 1114 NYU TandonDownload the code file hwa.py and rename it to YourNetID_hwa.py. You will modifythis file as specified in the problems below, and submit it to Gradescope.Modify the file only as specified in the problems, by replacing the pass lines as instructed.Do not modify any other areas of the file.IntroductionRead the provided code file thoroughly.In it, we present two Classes: Point, for representing a point in two-dimensional space;and Rectangle, for representing a rectangle.Each instance of Point contains a pair of floats. This should be intuitive to you.Each Point knows how to draw itself using the draw method. For example, I can createa Point and make it draw with the following code: p = Point(70.0, 10.0) p.draw()Each Point can also move itself with its move method. In the following code, I createa new Point instance, print out its coordinates, move it, and then print out its newcoordinates. p = Point(10.0, 20.0) print(p.x, p.y)10.0 20.0 p.move(7.0, -5.0) print(p.x, p.y)17.0 15.0Note that the move method updates the value stored in the instance of Point, but it doesnot change the position of any point drawn on the screen. Therefore, drawing the point,then moving it, then drawing it again, will result in two distinct points appearing on thescreen.Read and then run the Point_move_test function from the file to observe the effect ofvarious methods on Point.1ProblemsProblem 1You have been given an incomplete implementation of a Rectangle class, which describesa rectangle on a two-dimensional plane.Rectangle is defined in terms of Point. Each instance of Rectangle has two membervariables, both of type Point. For example, if I have two Points, one at coordinate20, 40, and the other at 70, 10, we can identify the following Rectangle:lowerright (70, 10)upperleft (20, 40)Note that the position of the remaining two corners of the rectangle can be inferred fromthe position of the two given.Complete the height and area methods of Rectangle, according to the specificationgiven in the code.Your area method must be implemented by calling the Rectangles height and widthmethods. Do not access the underlying Points directly.Problem 2Complete the diagonal_length Method of Rectangle, according to the specificationgiven in the code.You must implement diagonal_length by calling Points distance method. You maynot use the math.sqrt or the exponentiation operators directly in your code.Test your code by running the function rectangle_area_test. If youve implementedheight, area, and diagonal_length correctly, you should get this output: rectangle_area_test()r1 has width 110.0r1 has height 110.0r1 has area 12100.0r1 has diagonal length: 155.56349186104046(The final value is approximate; your answer may have fewer decimal places.)Problem 3Complete the move and draw methods of Rectangle, according to the specification givenin the code.The draw method draws a rectangle on the turtle canvas according to the current valuesstored in the Rectangle instance. You must implement draw by using only the followingturtle functions: turtle.penup, turtle.pendown, and turtle.goto.The move method just changes the location of the rectangle (i.e. of both of its points) bythe horizontal and vertical offsets specified in its parameters. The function does not draw,2and your implementation may not use turtle at all. You must implement move by callingPoints move method. Test your code by running the function rectangle_move_test. Ifyouve implemented the methods correctly, you should get this output:Problem 4Complete the overlaps method of Rectangle, according to the specification given in thecode.The overlaps method should return a bool indicating if a given Rectangle (identifiedby the parameter other) overlaps (i.e. shares area) with the present rectangle (identifiedby the parameter self). It Should return a bool.Hint: consider overlapping in the following manner.If a rectangle is entirely to the left of another rectangle (i.e. its rightmost point isto the left of the others leftmost point), then they dont overlap.If a rectangle is entirely to the right of another rectangle (i.e. its leftmost point isto the right of the others rightmost point), then they dont overlap. If a rectangle is entirely above another rectangle (i.e. its bottommost point is abovethe others topmost point), then they dont overlap.If a rectangle is entirely below another rectangle (i.e. its topmost point is below theothers bottommost point), then they dont overlap.If none of the above conditions apply, then they overlap.Test your code by running the function overlap_test. If youve implemented the methodscorrectly, you should get this output: overlap_test()r1 and r2 overlap? Truer3 and r4 overlap? FalseProblem 5Complete the intersection method of Rectangle, according to the specification givenin the code.The intersection method should return a new Rectangle instance, identifying the areathat is shared between other and self. If they dont overlap, then it should return anempty Rectangle.This function has already been partly implemented for you. Notice that it calls overlaps,so make sure that youve correctly implemented that function first.3Hint: you may want to use the min and max functions.Test your code by running the function intersection_test. If youve implemented themethods correctly, you Should get this output:Area of interesection: 600.0Notice the small red rectangle formed by the intersection of the black rectangles.Problem 6You have been given an incomplete implementation of the Line class. Complete the Lineclass according to the following specification.Each instance of Line should identify a line on a two-dimensional plane. It must havethe following methods:The constructor (def __init__(self, first, second)) must take self as wellas two additional parameters, both of type Point.The method draw (def draw(self)) takes no parameters except self and returnsNone. It should draw the line on the turtle canvas, using only the following functions:turtle.penup, turtle.pendown, and turtle.goto.The method slope (def slope(self)) takes no parameters except self and returnsa float identifying the slope of the current line. If the line has no slope, raisea ValueError with an appropriate message.Test your code by running the Function line_slope_test. If youve implemented themethods correctly, you should getthis output: line_slope_test()l1 has slope 1.0l2 has slope -0.5请加QQ:99515681 或邮箱:99515681@qq.com WX:codehelp

添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导