-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslope.py
40 lines (26 loc) · 842 Bytes
/
slope.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import math
#Function Define Coordinates
def getCoordinates(n):
print("Insert Coordinates")
x1 = input("x1=")
y1 = input("y1=")
if n == 1:
return x1, y1
elif n == 2:
x2 = input("x2=")
y2 = input("y2=")
return x1, y1, x2, y2
else:
x3 = input("x3=")
y3 = input("y3=")
return x1, y1, x2, y2, x3, y3
#Calculate slope
coordinates = getCoordinates(1)
#slope = y/x
slope = int(coordinates[1])/int(coordinates[0])
print("Slope = ", slope)
#Calculate slope between two points
coordinates = getCoordinates(2)
#slope = (y2-y1)/(x2-x1)
slope = (int(coordinates[3])-int(coordinates[1]))/(int(coordinates[2])-int(coordinates[0]))
print("Slope between two points = ", slope)