-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythagoreanTriple.py
More file actions
124 lines (104 loc) · 3.49 KB
/
PythagoreanTriple.py
File metadata and controls
124 lines (104 loc) · 3.49 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#This one took longer
#Pretty messy but it works
import math
def consecutive_pythag_therom(num):
#num = math.sqrt(a2+b2)
left_side_equation = (num**2 + (num+1)**2)
right_side_equation = ((num+2)**2)
if left_side_equation == right_side_equation: #if there's a remainder (if this isn't a right triangle)
return True
else:
pass
def n_plus_one_pythag_therom(a): #pretty sure this is accurate
#num = math.sqrt(a2+b2)
n = ((1 - a ** 2) / -2)
a = math.sqrt(((n + 1) ** 2) - n ** 2)
return a, n
#BONUS EQUATIONS
def n_plus_two_pythag_therom(a): #not sure how accurate this formula is
#num = math.sqrt(a2+b2)
n = (((a ** 2)/4))
a = math.sqrt(((n + 2) ** 2) - n ** 2)
return a, n
def n_plus_three_pythag_therom(a): #not sure how accurate this formula is
#num = math.sqrt(a2+b2)
n = (3 - (a ** 2))
c = ((n + 3) ** 2)
print(c)
print(n)
print(a)
a = math.sqrt((n**2)-c )
return a, n
## FIND FUNCTIONS ###
def find_consecutive_triples(range):
num = -100
count =0
while num < range: #go crazy on the zeros, or set to True
b2 = (num +1)**2
a2 = num**2
if consecutive_pythag_therom(num): #if the triple is a triangle
count += 1
print("Triple #" + str(count) + " Found!!")
print("The Triple is: (" + str(num) + ", " + str(num+1) + ", " + str(num+2)+")")
num += 1
def find_n_plus_one_triples(range):
a = 1
count = 0
while a < range: #go crazy
if a % 2 == 0: #if a is even
pass
else:
a,b = (n_plus_one_pythag_therom(a))
print("Triple #" + str(count) + " Found!!")
print("The Triple is: (" + str(a) + ", " + str(b) + ", " + str(b + 1) + ")")
a+=1
count+=1
def find_n_plus_two_triples(range):
a = 1
count = 0
while a < range: #go crazy
if a % 2 == 0: #if a is even
pass
else:
a,b = (n_plus_three_pythag_therom(a))
print("Triple #" + str(count) + " Found!!")
print("The Triple is: (" + str(a) + ", " + str(b) + ", " + str(b + 2) + ")")
a+=1
count+=1
def find_n_plus_three_triples(range):
a = 1
count = 0
while a < range: #go crazy
if a % 2 == 0: #if a is even
pass
else:
a,b = (n_plus_three_pythag_therom(a))
print("Triple #" + str(count) + " Found!!")
print("The Triple is: (" + str(a) + ", " + str(b) + ", " + str(b + 3) + ")")
a+=1
count+=1
# FIND FUNCTIONS #
running = True
while running:
print("Hey Mr. Hornbeck...I think?\nWould you like to see:"
"\n1.) N+1 triples?"
"\n2.) N+2 Triples? broken"
"\n3.) N+3 Triples? broken ")
user = input("Enter a number: ")
user = int(user)
if user == 1:
range = int(input("Enter Max Range to generate: "))
range = int(range)
find_n_plus_one_triples(range)
elif user == 2:
range = int(input("Enter Max Range to generate: "))
find_n_plus_two_triples(range)
elif user == 3:
range = int(input("Enter Max Range to generate: "))
find_n_plus_three_triples(range)
user = input("Do you want to continue? Enter yes/no: ")
if user == 'yes' or user == 'y':
running = True
else:
running = False
print("hope this was nice")