I really don't understand classes very much and any help would be great.
Rectangle class should have the following private data attributes:
__length
__width
The Rectangle class should have an __init__
method that creates these attributes and initializes them to 1. It should also have the following methods:
set_length
– this method assigns a value to the__length
fieldset_width
– this method assigns a value to the__width
fieldget_length
– this method returns the value of the__length
fieldget_width
– this method returns the value of the__width
fieldget_area
– this method returns the area of Rectangle__str__
– this method returns the object’s state
class Rectangle:
def __init__(self):
self.set_length = 1
self.set_width = 1
self.get_length = 1
self.get_width = 1
self.get_area = 1
def get_area(self):
self.get_area = self.get_width * self.get_length
return self.get_area
def main():
my_rect = Rectangle()
my_rect.set_length(4)
my_rect.set_width(2)
print('The length is',my_rect.get_length())
print('The width is', my_rect.get_width())
print('The area is',my_rect.get_area())
print(my_rect)
input('press enter to continue')