Solution 1

```
class Point(object):
def __init__(self, x, y):
self.x = x
self.y = y
class Line(object):
def __init__(self, p1, p2):
self.p1 = p1
self.p2 = p2
def slope(self):
return (self.p2.y - self.p1.y) / (self.p2.x - self.p1.x)
def y_intercept(self):
m = self.slope()
return self.p1.y - (m * self.p1.x)
def formula(self):
tpl = 'y = {m}x + {b:g}'
m = self.slope()
if m == 1:
m = ''
return tpl.format(m=m, b=self.y_intercept())
```

# Points and Lines

Time to make things a bit more complicated. Now you need to write *two* classes!

Create a class `Point`

that receives two parameters `x`

and `y`

and stores them within each point created.

Next create a class `Line`

that receives two points as parameters `p1`

and `p2`

.

It needs the following 3 methods:

* slope that returns the slope of the line based on the two points
Equation: (y2 - y1)/(x2 - x1)
*

`y_intercept`

that returns the y-intercept of the lineEquation:

**y1 - (slope * x1)**

*

`formula`

that returns a string of the formula of the line (if the slope is 1, omit it).Equation:

**y = mx + b**where m is slope and b is y-intercept

Note: None of these methods receive any external parameters

For the `formula`

string, if the y-intercept can be truncated (e.g. using 1 instead of 1.0), do it using {:g} in your string formatting.

```
"{b:g}".format(b=3.0) # 3
"{b:g}".format(b=3.2) # 3.2
```

Example:

```
p1 = Point(0, 1)
p2 = Point(1, 2)
l = Line(p1, p2)
l.slope() # 1
l.y_intercept() # 1
l.formula() # 'y = x + 1.0'
```