Write an empty class Rectangle
that defines a rectangle:
- You are not allowed to import any module
Write a class Rectangle
that defines a rectangle by: (based on 0-rectangle.py
)
- Private instance attribute:
width
:- property
def width(self):
to retrieve it - property setter
def width(self, value):
to set it:width
must be an integer, otherwise raise aTypeError
exception with the messagewidth must be an integer
- if
width
is less than0
, raise aValueError
exception with the messagewidth must be >= 0
- property
- Private instance attribute:
height
:- property
def height(self):
to retrieve it - property setter
def height(self, value):
to set it:height
must be an integer, otherwise raise aTypeError
exception with the messageheight must be an integer
- if
height
is less than0
, raise aValueError
exception with the messageheight must be >= 0
- property
- Instantiation with optional
width
andheight
:def __init__(self, width=0, height=0):
- You are not allowed to import any module
Write a class Rectangle
that defines a rectangle by: (based on 1-rectangle.py
)
- Private instance attribute:
width
:- property
def width(self):
to retrieve it - property setter
def width(self, value):
to set it:width
must be an integer, otherwise raise aTypeError
exception with the messagewidth must be an integer
- if
width
is less than0
, raise aValueError
exception with the messagewidth must be >= 0
- property
- Private instance attribute:
height
:- property
def height(self):
to retrieve it - property setter
def height(self, value):
to set it:height
must be an integer, otherwise raise aTypeError
exception with the messageheight must be an integer
- if
height
is less than0
, raise aValueError
exception with the messageheight must be >= 0
- property
- Instantiation with optional width and height:
def __init__(self, width=0, height=0):
- Public instance method:
def area(self):
that returns the rectangle area - Public instance method:
def perimeter(self):
that returns the rectangle perimeter:- if
width
orheight
is equal to0
, perimeter is equal to0
- if
- You are not allowed to import any module
Write a class Rectangle
that defines a rectangle by: (based on 2-rectangle.py
)
- Private instance attribute:
width
:- property
def width(self):
to retrieve it - property setter
def width(self, value):
to set it:width
must be an integer, otherwise raise aTypeError
exception with the messagewidth must be an integer
- if
width
is less than0
, raise aValueError
exception with the messagewidth must be >= 0
- property
- Private instance attribute:
height
:- property
def height(self):
to retrieve it - property setter
def height(self, value):
to set it:height
must be an integer, otherwise raise aTypeError
exception with the messageheight must be an integer
- if
height
is less than0
, raise aValueError
exception with the messageheight must be >= 0
- property
- Instantiation with optional width and height:
def __init__(self, width=0, height=0):
- Public instance method:
def area(self):
that returns the rectangle area - Public instance method:
def perimeter(self):
that returns the rectangle perimeter:- if
width
orheight
is equal to0
, perimeter has to be equal to0
- if
- print() and str() should print the rectangle with the character
#
:- if
width
orheight
is equal to 0, return an empty string
- if
- You are not allowed to import any module
Write a class Rectangle
that defines a rectangle by: (based on 3-rectangle.py
)
- Private instance attribute:
width
:- property
def width(self):
to retrieve it - property setter
def width(self, value):
to set it:width
must be an integer, otherwise raise aTypeError
exception with the messagewidth must be an integer
- if
width
is less than0
, raise aValueError
exception with the messagewidth must be >= 0
- property
- Private instance attribute:
height
:- property
def height(self):
to retrieve it - property setter
def height(self, value):
to set it:height
must be an integer, otherwise raise aTypeError
exception with the message height must be an integer
- if
height
is less than0
, raise aValueError
exception with the messageheight must be >= 0
- property
- Instantiation with optional
width
andheight
:def __init__(self, width=0, height=0):
- Public instance method:
def area(self):
that returns the rectangle area - Public instance method:
def perimeter(self):
that returns the rectangle perimeter:- if
width
orheight
is equal to0
, perimeter has to be equal to0
- if
print()
andstr()
should print the rectangle with the character#
:- if
width
orheight
is equal to 0, return an empty string
- if
repr()
should return a string representation of the rectangle to be able to recreate a new instance by usingeval()
- You are not allowed to import any module
Write a class Rectangle
that defines a rectangle by: (based on 4-rectangle.py
)
- Private instance attribute:
width
:- property
def width(self):
to retrieve it - property setter
def width(self, value):
to set it:width
must be an integer, otherwise raise aTypeError
exception with the messagewidth must be an integer
- if
width
is less than0
, raise aValueError
exception with the messagewidth must be >= 0
- property
- Private instance attribute:
height
:- property
def height(self):
to retrieve it - property setter
def height(self, value):
to set it:height
must be an integer, otherwise raise aTypeError
exception with the messageheight must be an integer
- if
height
is less than0
, raise aValueError
exception with the messageheight must be >= 0
- property
- Instantiation with optional
width
andheight
:def __init__(self, width=0, height=0):
- Public instance method:
def area(self):
that returns the rectangle area - Public instance method:
def perimeter(self):
that returns the rectangle perimeter:- if
width
orheight
is equal to0
, perimeter has to be equal to0
- if
print()
andstr()
should print the rectangle with the character#
:- if
width
orheight
is equal to 0, return an empty string
- if
repr()
should return a string representation of the rectangle to be able to recreate a new instance by usingeval()
- Print the message
Bye rectangle...
(...
being 3 dots not ellipsis) when an instance ofRectangle
is deleted - You are not allowed to import any module
Write a class Rectangle
that defines a rectangle by: (based on 5-rectangle.py
)
- Private instance attribute:
width
:- property
def width(self):
to retrieve it - property setter
def width(self, value):
to set it:width
must be an integer, otherwise raise aTypeError
exception with the messagewidth must be an integer
- if
width
is less than0
, raise aValueError
exception with the messagewidth must be >= 0
- property
- Private instance attribute:
height
:- property
def height(self):
to retrieve it - property setter
def height(self, value):
to set it:height
must be an integer, otherwise raise aTypeError
exception with the messageheight must be an integer
- if
height
is less than0
, raise aValueError
exception with the messageheight must be >= 0
- property
- Public class attribute
number_of_instances
:- Initialized to
0
- Incremented during each new instance instantiation
- Decremented during each instance deletion
- Initialized to
- Instantiation with optional
width
andheight
:def __init__(self, width=0, height=0):
- Public instance method:
def area(self):
that returns the rectangle area - Public instance method:
def perimeter(self):
that returns the rectangle perimeter:- if
width
orheight
is equal to0
, perimeter has to be equal to0
- if
print()
andstr()
should print the rectangle with the character#
:- if
width
orheight
is equal to 0, return an empty string
- if
repr()
should return a string representation of the rectangle to be able to recreate a new instance by usingeval()
- Print the message
Bye rectangle...
(...
being 3 dots not ellipsis) when an instance ofRectangle
is deleted - You are not allowed to import any module
Write a class Rectangle
that defines a rectangle by: (based on 6-rectangle.py
)
- Private instance attribute:
width
:- property
def width(self):
to retrieve it - property setter
def width(self, value):
to set it:width
must be an integer, otherwise raise aTypeError
exception with the messagewidth must be an integer
- if
width
is less than0
, raise aValueError
exception with the messagewidth must be >= 0
- property
- Private instance attribute:
height
:- property
def height(self):
to retrieve it - property setter
def height(self, value):
to set it:height
must be an integer, otherwise raise aTypeError
exception with the messageheight must be an integer
- if
height
is less than0
, raise aValueError
exception with the messageheight must be >= 0
- property
- Public class attribute
number_of_instances
:- Initialized to
0
- Incremented during each new instance instantiation
- Decremented during each instance deletion
- Initialized to
- Public class attribute
print_symbol
:- Initiliazed to
#
- Used as symbol for string representation
- Can be any type
- Initiliazed to
- Instantiation with optional
width
andheight
:def __init__(self, width=0, height=0):
- Public instance method:
def area(self):
that returns the rectangle area - Public instance method:
def perimeter(self):
that returns the rectangle perimeter:- if
width
orheight
is equal to0
, perimeter has to be equal to0
- if
print()
andstr()
should print the rectangle with the character(s) stored inprint_symbol
:- if
width
orheight
is equal to 0, return an empty string
- if
repr()
should return a string representation of the rectangle to be able to recreate a new instance by usingeval()
- Print the message
Bye rectangle...
(...
being 3 dots not ellipsis) when an instance ofRectangle
is deleted - You are not allowed to import any module
Write a class Rectangle
that defines a rectangle by: (based on 7-rectangle.py
)
- Private instance attribute:
width
:- property
def width(self):
to retrieve it - property setter
def width(self, value):
to set it:width
must be an integer, otherwise raise aTypeError
exception with the messagewidth must be an integer
- if
width
is less than0
, raise aValueError
exception with the messagewidth must be >= 0
- property
- Private instance attribute:
height
:- property
def height(self):
to retrieve it - property setter
def height(self, value):
to set it:height
must be an integer, otherwise raise aTypeError
exception with the messageheight must be an integer
- if
height
is less than0
, raise aValueError
exception with the messageheight must be >= 0
- property
- Public class attribute
number_of_instances
:- Initialized to
0
- Incremented during each new instance instantiation
- Decremented during each instance deletion
- Initialized to
- Public class attribute
print_symbol
:- Initiliazed to
#
- Used as symbol for string representation
- Can be any type
- Initiliazed to
- Instantiation with optional
width
andheight
:def __init__(self, width=0, height=0):
- Public instance method:
def area(self):
that returns the rectangle area - Public instance method:
def perimeter(self):
that returns the rectangle perimeter:- if
width
orheight
is equal to0
, perimeter has to be equal to0
- if
print()
andstr()
should print the rectangle with the character#
:- if
width
orheight
is equal to 0, return an empty string
- if
repr()
should return a string representation of the rectangle to be able to recreate a new instance by usingeval()
- Print the message
Bye rectangle...
(...
being 3 dots not ellipsis) when an instance ofRectangle
is deleted - Static method
def bigger_or_equal(rect_1, rect_2):
that returns the biggest rectangle based on the arearect_1
must be an instance of Rectangle, otherwise raise aTypeError
exception with the messagerect_1 must be an instance of Rectangle
rect_2
must be an instance ofRectangle
, otherwise raise aTypeError
exception with the messagerect_2 must be an instance of Rectangle
- Returns
rect_1
if both have the same area value
- You are not allowed to import any module
Write a class Rectangle
that defines a rectangle by: (based on 8-rectangle.py
)
- Private instance attribute:
width
:- property
def width(self):
to retrieve it - property setter
def width(self, value):
to set it:width
must be an integer, otherwise raise aTypeError
exception with the messagewidth must be an integer
- if
width
is less than0
, raise aValueError
exception with the messagewidth must be >= 0
- property
- Private instance attribute:
height
:- property
def height(self):
to retrieve it - property setter
def height(self, value):
to set it:height
must be an integer, otherwise raise aTypeError
exception with the messageheight must be an integer
- if
height
is less than0
, raise aValueError
exception with the messageheight must be >= 0
- property
- Public class attribute
number_of_instances
:- Initialized to
0
- Incremented during each new instance instantiation
- Decremented during each instance deletion
- Initialized to
- Public class attribute
print_symbol
:- Initiliazed to
#
- Used as symbol for string representation
- Can be any type
- Initiliazed to
- Instantiation with optional
width
andheight
:def __init__(self, width=0, height=0):
- Public instance method:
def area(self):
that returns the rectangle area - Public instance method:
def perimeter(self):
that returns the rectangle perimeter:- if
width
orheight
is equal to0
, perimeter has to be equal to0
- if
print()
andstr()
should print the rectangle with the character#
:- if
width
orheight
is equal to 0, return an empty string
- if
repr()
should return a string representation of the rectangle to be able to recreate a new instance by usingeval()
- Print the message
Bye rectangle...
(...
being 3 dots not ellipsis) when an instance ofRectangle
is deleted - Static method
def bigger_or_equal(rect_1, rect_2):
that returns the biggest rectangle based on the arearect_1
must be an instance of Rectangle, otherwise raise aTypeError
exception with the messagerect_1 must be an instance of Rectangle
rect_2
must be an instance ofRectangle
, otherwise raise aTypeError
exception with the messagerect_2 must be an instance of Rectangle
- Returns
rect_1
if both have the same area value
- Class method
def square(cls, size=0):
that returns a new Rectangle instance withwidth == height == size
- You are not allowed to import any module