-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrig.py
More file actions
77 lines (66 loc) · 2.5 KB
/
trig.py
File metadata and controls
77 lines (66 loc) · 2.5 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
import math
#Strings to print out as results
scalene = "Scalene Triangle"
equilateral = "Equilateral Triangle"
right = "Right Triangle"
notTri = "Not a Triangle"
isosceles = "Isosceles Triangle"
#Runs if user gives side lengths instead of points
def givenLengths(side1, side2, side3):
#Makes it so that the lengths can be put in any order and still get the right results
l1 = max(side1, side2, side3)
l3 = min(side1, side2, side3)
l2 = (side1 + side2 + side3) - l1 - l3
#Finds out what type of triangle it is
if (((l2 + l3) > l1) and ((l1 + l2) > l3) and ((l1 + l3) > l2)):
if ((l1 ** 2) == (l2 ** 2) + (l3 ** 2)):
return right
elif (l1 == l2 == l3):
return equilateral
elif ((l1 != l2) and (l1 != l3) and (l3 != l2)):
return scalene
elif ((l1 == l2) or (l1 == l3) or (l2 == l3)):
return isosceles
else:
return notTri
else:
return notTri
#Runs if user gives points instead of side lengths
def givenPoints(x1, y1, x2, y2, x3, y3):
#Gets length of sides, plugs into givenLengths() to get triangle type
dist1 = math.sqrt(((x2 - x1) ** 2) + ((y2 - y1) ** 2))
dist2 = math.sqrt(((x3 - x2) ** 2) + ((y3 - y2) ** 2))
dist3 = math.sqrt(((x3 - x1) ** 2) + ((y3 - y1) ** 2))
triType = givenLengths(dist1, dist2, dist3)
return(dist1, dist2, dist3, triType)
#Runs terminal version of program
def main():
#Find out if user wants to use points or lengths of sides
while True:
getInput = input("Find the triangle with lengths (1) or points (2)? ")
if(getInput == "lengths" or getInput == "1"):
wanted = 1
break
elif(getInput == "points" or getInput == "2"):
wanted = 2
break
else:
print("Choose a real selection: ")
#Ask details about side lenths
if (wanted == 1):
side1 = float(input("What is side 1? "))
side2 = float(input("What is side 2? "))
side3 = float(input("What is side 3? "))
print(givenLengths(side1, side2, side3))
#Details if wants to use points
else:
x1 = float(input("What is x1? "))
y1 = float(input("What is y1? "))
x2 = float(input("What is x2? "))
y2 = float(input("What is y2? "))
x3 = float(input("What is x3? "))
y3 = float(input("What is y3? "))
print(givenPoints(x1, y1, x2, y2, x3, y3))
#If file is run as standalone, run main() function
if __name__ == "__main__":
main()