Question: Question: Type a version of move_rectangle that creates and returns a new Rectangle instead of modifying the old one. Rectangle should have the following

Question: Type a version of move_rectangle that creates and returns a new Rectangle instead of modifying the old one.

 

Rectangle should have the following dimensions:
width = 100.00
height = 200.00

 

The location of the corner is:
x = 50
y = 50

 

Move the rectangle by the following
x = 50
y = 100The old rectangle should retain the original location.

 

 

Expected Outcome(output):

First box location before move:
50.0
50.0
New box with new location:
100.0
150.0
Old box location:
50.0
50.0

 

python file:

 

import copy

import math






 

def move_rectangle(box, dx, dy):

  """Move the Rectangle by modifying its corner object.

  rect: Rectangle object.

  dx: change in x coordinate (can be negative).

  dy: change in y coordinate (can be negative).

  """

  box.corner.x += dx

  box.corner.y += dy

 

def move_rectangle_copy(box, dx, dy):

    """Move the Rectangle and return a new Rectangle object.

    rect: Rectangle object.

    dx: change in x coordinate (can be negative).

    dy: change in y coordinate (can be negative).

    returns: new Rectangle

    """



 

    return new


 

def main():






 

    print('First box location before move:')




 

    print('New box with new location:')



 

   

    print('Old box location:')




 

if __name__ == '__main__':

    main()  

 




Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Sure Heres a possible implementation of moverectanglecopy def moverectanglecopybox dx dy newbox copy... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!