Advertisement
40080226

Rectangle Class

Jan 18th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. class Rectangle:
  2.    
  3.     def __init__(self,x,y):
  4.         self.x=x
  5.         self.y=y
  6.    
  7.     def __str__(self):
  8.         s= "Length = " + str(self.x) +  " Width = " +str(self.y)
  9.         return s
  10.    
  11.     def area(self):
  12.         A=self.x*self.y
  13.         return A
  14.    
  15.     def perimeter(self):
  16.         P=2*self.x + 2*self.y
  17.         return P
  18.    
  19.  
  20. R1=Rectangle(4,5)    
  21. print R1.area()
  22. print R1.perimeter()
  23. print R1
  24.  
  25. R1=Rectangle(16,7)    
  26. print R1.area()
  27. print R1.perimeter()
  28. print R1
  29.  
  30. x = int(input("Enter the value of x"))
  31. y = int(input("Enter the value of y"))
  32.  
  33. R1=Rectangle(x,y)    
  34. print R1.area()
  35. print R1.perimeter()
  36. print R1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement