mariang_09

Untitled

Nov 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. from math import sqrt
  2.  
  3. class Line(object):
  4.    
  5.     def __init__(self,coor1,coor2):
  6.         self.coor1 = coor1
  7.         self.coor2 = coor2
  8.    
  9.     def distance(self):
  10.         return sqrt((self.coor2[1] - self.coor1[1])**2 + (self.coor2[0] - self.coor1[0])**2)
  11.    
  12.     def slope(self):
  13.         return (self.coor2[1] - self.coor1[1]) / (self.coor2[0] - self.coor1[0])
  14.  
  15. coordinate1 = (5, 6)
  16. coordinate2 = (10, 11)
  17.  
  18. li = Line(coordinate1, coordinate2)
  19.  
  20. print("The line distance is:", li.distance())
  21. print("The line's gradient is:", li.slope())
  22.  
  23. class Cylinder(object):
  24.  
  25.     pi = 3.14
  26.  
  27.     def __init__(self, height = 1, radius = 1):
  28.         self.height = height
  29.         self.radius = radius
  30.  
  31.     def volume(self):
  32.         return Cylinder.pi * self.radius**2 * self.height
  33.  
  34.     def surface_area(self):
  35.         return 2 * Cylinder.pi * self.radius * self.height + 2 * Cylinder.pi * self.radius**2
  36.  
  37. c = Cylinder(5, 6)
  38.  
  39. print("The volume is:", c.volume())
  40. print("The area is:", c.surface_area())
Add Comment
Please, Sign In to add comment