class Square( object ) :
def __init__ ( self , side, colour= "black" ) :
self .side = side
self .colour = colour
@ property
def area( self ) :
return self .side ** 2
@ area.setter
def area( self , value) :
self .side = value ** 0.5
@ property
def perimeter( self ) :
return self .side * 4
@ perimeter.setter
def perimeter( self , value) :
self .side = value / 4.0
def __repr__ ( self ) :
return "%s square with the side: %.2f, area: %.2f, perimeter: %.2f" % (
self .colour .title ( ) , self .side , self .area , self .perimeter )
square = Square( 8 )
print ( square)
square.side = 40
print ( square)
square.colour = "yellow"
square.area = 89
print ( square)
square.perimeter = 134.6
print ( square)
Y2xhc3MgU3F1YXJlKG9iamVjdCk6CiAgICBkZWYgX19pbml0X18oc2VsZiwgc2lkZSwgY29sb3VyPSJibGFjayIpOgogICAgICAgIHNlbGYuc2lkZSA9IHNpZGUKICAgICAgICBzZWxmLmNvbG91ciA9IGNvbG91cgogICAgICAgIAogICAgQHByb3BlcnR5CiAgICBkZWYgYXJlYShzZWxmKToKICAgICAgICByZXR1cm4gc2VsZi5zaWRlICoqIDIKICAgIAogICAgQGFyZWEuc2V0dGVyCiAgICBkZWYgYXJlYShzZWxmLCB2YWx1ZSk6CiAgICAgICAgc2VsZi5zaWRlID0gdmFsdWUgKiogMC41CiAgICAKICAgIEBwcm9wZXJ0eQogICAgZGVmIHBlcmltZXRlcihzZWxmKToKICAgICAgICByZXR1cm4gc2VsZi5zaWRlICogNAogICAgCiAgICBAcGVyaW1ldGVyLnNldHRlcgogICAgZGVmIHBlcmltZXRlcihzZWxmLCB2YWx1ZSk6CiAgICAgICAgc2VsZi5zaWRlID0gdmFsdWUgLyA0LjAKICAgIAogICAgZGVmIF9fcmVwcl9fKHNlbGYpOgogICAgICAgIHJldHVybiAiJXMgc3F1YXJlIHdpdGggdGhlIHNpZGU6ICUuMmYsIGFyZWE6ICUuMmYsIHBlcmltZXRlcjogJS4yZiIgJSAoCiAgICAgICAgICAgIHNlbGYuY29sb3VyLnRpdGxlKCksIHNlbGYuc2lkZSwgc2VsZi5hcmVhLCBzZWxmLnBlcmltZXRlcikKICAgICAgICAgICAgCnNxdWFyZSA9IFNxdWFyZSg4KQpwcmludChzcXVhcmUpCgpzcXVhcmUuc2lkZSA9IDQwCnByaW50KHNxdWFyZSkKCnNxdWFyZS5jb2xvdXIgPSAieWVsbG93IgpzcXVhcmUuYXJlYSA9IDg5CnByaW50KHNxdWFyZSkKCnNxdWFyZS5wZXJpbWV0ZXIgPSAxMzQuNgpwcmludChzcXVhcmUp
stdout
Black square with the side: 8.00, area: 64.00, perimeter: 32.00
Black square with the side: 40.00, area: 1600.00, perimeter: 160.00
Yellow square with the side: 9.43, area: 89.00, perimeter: 37.74
Yellow square with the side: 33.65, area: 1132.32, perimeter: 134.60