Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import sqrt
- class Line(object):
- def __init__(self,coor1,coor2):
- self.coor1 = coor1
- self.coor2 = coor2
- def distance(self):
- return sqrt((self.coor2[1] - self.coor1[1])**2 + (self.coor2[0] - self.coor1[0])**2)
- def slope(self):
- return (self.coor2[1] - self.coor1[1]) / (self.coor2[0] - self.coor1[0])
- coordinate1 = (5, 6)
- coordinate2 = (10, 11)
- li = Line(coordinate1, coordinate2)
- print("The line distance is:", li.distance())
- print("The line's gradient is:", li.slope())
- class Cylinder(object):
- pi = 3.14
- def __init__(self, height = 1, radius = 1):
- self.height = height
- self.radius = radius
- def volume(self):
- return Cylinder.pi * self.radius**2 * self.height
- def surface_area(self):
- return 2 * Cylinder.pi * self.radius * self.height + 2 * Cylinder.pi * self.radius**2
- c = Cylinder(5, 6)
- print("The volume is:", c.volume())
- print("The area is:", c.surface_area())
Add Comment
Please, Sign In to add comment