本文整理匯總了Python中rectangle.Rectangle.perimeter方法的典型用法代碼示例。如果您正苦於以下問題:Python Rectangle.perimeter方法的具體用法?Python Rectangle.perimeter怎麽用?Python Rectangle.perimeter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rectangle.Rectangle
的用法示例。
在下文中一共展示了Rectangle.perimeter方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: RectangleTest
# 需要導入模塊: from rectangle import Rectangle [as 別名]
# 或者: from rectangle.Rectangle import perimeter [as 別名]
class RectangleTest(unittest.TestCase):
def setUp(self):
self.rectangle = Rectangle(width=3, height=2)
def test_it_has_width_and_height(self):
self.rectangle.width |should| equal_to(3)
self.rectangle.height |should| equal_to(2)
def test_it_changes_its_width(self):
self.rectangle.width = 5
self.rectangle.width |should| equal_to(5)
def test_it_changes_its_height(self):
self.rectangle.height = 5
self.rectangle.height |should| equal_to(5)
def test_it_calculates_its_area(self):
self.rectangle.area() |should| equal_to(6)
def test_it_calculates_its_perimeter(self):
self.rectangle.perimeter() |should| equal_to(10)
示例2: printvalue
# 需要導入模塊: from rectangle import Rectangle [as 別名]
# 或者: from rectangle.Rectangle import perimeter [as 別名]
from rectangle import Rectangle
def printvalue(values):
values.perimeter()
print
values.area()
print
firstrec = Rectangle()
secondrec = Rectangle(8.5,12.2)
thirdrec = Rectangle(10.6,10.1)
secondrec.display()
print "for first rectangle, values are perimeter and area respectively",
firstrec.perimeter()
print "for second rectangle, values are perimeter and area respectively",
printvalue(secondrec)
print "for third rectangle, values are perimeter and area respectively",
printvalue(thirdrec)