-
Notifications
You must be signed in to change notification settings - Fork 0
/
testgeom.py
65 lines (54 loc) · 1.87 KB
/
testgeom.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File geotest.py
################################################################
# You should not modify anything in this file
################################################################
from geometry import distance, slope, intercept, lineequation, inf
def print_point(x, y):
print("(", x, ",", y, ")", sep="", end="")
def do_distance(x1, y1, x2, y2):
print(end="The distance between ")
print_point(x1, y1)
print(end=" and ")
print_point(x2, y2)
print("is ", distance(x1, y1, x2, y2))
def do_slope(x1, y1, x2, y2):
print(end="The slope of the line between ")
print_point(x1, y1)
print(end=" and ")
print_point(x2, y2)
print(end=" is ")
m = slope(x1, y1, x2, y2)
if m == inf:
print("undefined")
else:
print(m)
def do_intercept(x1, y1, x2, y2):
if slope(x1, y1, x2, y2) == inf:
print(end="The x-")
else:
print(end="The y-")
print(end="intercept of the line between ")
print_point(x1, y1)
print(end=" and ")
print_point(x2, y2)
print(" is", intercept(x1, y1, x2, y2))
def do_equation(x1, y1, x2, y2):
print(end="The equation of the line between ")
print_point(x1, y1)
print(end=" and ")
print_point(x2, y2);
print(end=" is ")
print(lineequation(x1, y1, x2, y2))
def main():
print("Enter the coordinates of the two points")
while True: # Infinite loop, use Control-C to quit
p_x1 = float(input("Enter x1 (Control-C quits): "))
p_y1 = float(input("Enter y1 (Control-C quits): "))
p_x2 = float(input("Enter x2 (Control-C quits): "))
p_y2 = float(input("Enter y2 (Control-C quits): "))
do_distance(p_x1, p_y1, p_x2, p_y2)
do_slope(p_x1, p_y1, p_x2, p_y2)
do_intercept(p_x1, p_y1, p_x2, p_y2)
do_equation(p_x1, p_y1, p_x2, p_y2)
print("-----------------")
main() # Run main