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
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 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
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#
: (see example below)- 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 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#
: (see example below)- 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()
(see example below)- 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…” when an instance of
Rectangle
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…” when an instance of
Rectangle
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
:- Initialized to
#
- Used as symbol for string representation
- Can be any type
- 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…” when an instance of
Rectangle
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
:- Initialized to
#
- Used as symbol for string representation
- Can be any type
- 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…” when an instance of
Rectangle
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 ofRectangle
, 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
:- Initialized to
#
- Used as symbol for string representation
- Can be any type
- 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…” when an instance of
Rectangle
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 ofRectangle
, 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
Write a blog post describing how object and class attributes work.
- What’s a class attribute
- What’s an instance attribute
- What are all the way to create them and what is the Pythonic way of doing it
- What are the differences between class and instance attributes
- What are the advantages and drawbacks of each of them
- How does Python deal with the object and class attributes using the
__dic__
Your posts should have examples and at least one picture, at the top. Publish your blog post on Medium or LinkedIn, and share it at least on Twitter and LinkedIn.
When done, please add all urls below (blog post, tweet, etc.)
Chess grandmaster Judit Polgár, the strongest female chess player of all time
The N queens puzzle is the challenge of placing N non-attacking queens on an N×N chessboard. Write a program that solves the N queens problem.
- Usage:
nqueens N
- If the user called the program with the wrong number of arguments, print
Usage: nqueens N
, followed by a new line, and exit with the status1
- If the user called the program with the wrong number of arguments, print
- where N must be an integer greater or equal to
4
- If N is not an integer, print
N must be a number
, followed by a new line, and exit with the status1
- If N is smaller than
4
, printN must be at least 4
, followed by a new line, and exit with the status1
- If N is not an integer, print
- The program should print every possible solution to the problem
- One solution per line
- Format: see example
- You don’t have to print the solutions in a specific order
- You are only allowed to import the
sys
module
Read: Queen, Backtracking