0

I have written a program that will give a rectangle. I don't find the problem with your program. Can someone help me?

class Rectangle: def __init__ (self, point1: tuple=(0,0), point2: tuple=(1,1)): self.corner1 = point1 self.corner2 = point2 self.corner3 = (self.corner1[0], self.corner2[1]) self.corner4 = (self.corner2[0], self.corner1[1]) def __repr__ (self): list1=str([self.corner1, self.corner2, self.corner3, self.corner4]) return ("Rectangle's corners are : %s" %list1) def __str__ (self): return "dasdmck" def rotate (self, angel: float=90, measure: str="degree"): from math import pi from math import sin from math import cos list1=[self.corner1, self.corner2, self.corner3, self.corner4] list2=[] if measure == "rad": rad = angel else: rad= (angel * pi)/180 for i in list1: a = round(i[0] * cos(rad) + float(i[1]) * sin(rad), 3) b = round(i[1] * cos(rad) - float(i[0]) * sin(rad), 3) c=(a, b)

28th Jun 2020, 4:27 PM
Fatemeh Ghafouri
3 Answers
+ 3
????? ??????, i think it would be better to create an instance first. my_rect = Rectangle((1,1),(4,8)) print(my_rect.corner1, my_rect.corner2) my_rect.rotate(90) But i am not sure if rotate works correct. If i use Rectangle((1,1),(4,8)) and rotate it by 90 degrees, the coordinates seems to be the same.
28th Jun 2020, 7:15 PM
Lothar
Lothar - avatar
+ 1
The code for rotation posted by you is not complete: please copy it in SoloLearn playground for better examination. "c", the rotated point, must be assigned back to the rotated corner.
29th Jun 2020, 3:54 AM
Bilbo Baggins
Bilbo Baggins - avatar