-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactorization.py
More file actions
executable file
·111 lines (102 loc) · 3.19 KB
/
factorization.py
File metadata and controls
executable file
·111 lines (102 loc) · 3.19 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
def factorization(num):
if isinstance(num, (str, float)):
print("error, inputted value is not an integer")
else:
factors = []
import math
test = num
while test > 1:
mod = num%test
if mod == 0:
factors.append(test)
test -=1
print (factors)
def Greatest(num1, num2):
if isinstance(num1 or num2, (str, float)):
print("error, one or more inputted values is not an integer")
else:
import math
GCDnum = 1
num1Mult = num1-1
num2Mult = num2-1
factors = []
factorNum = num1-1
if num1%num2 == 0 or num2%num1 == 0:
if num1<=num2:
print ("The greatest common denominator is: ")
print (num1)
else:
print ("The greatest common denominator is: ")
print (num2)
else:
while num1Mult > 1:
mod = num1%num1Mult
if mod == 0:
factors.append(num1Mult)
num1Mult -=1
while num2Mult > 1:
mod = num2%num2Mult
if mod == 0:
factors.append(num2Mult)
num2Mult -=1
while GCDnum == 1:
if factors.count(factorNum) == 2:
GCDnum = factorNum
else:
factorNum-=1
print ("The greatest common multiple is :")
print (GCDnum)
def Least(num1, num2):
if isinstance(num1 or num2, (str, float)):
print("error, one or more inputted values is not an integer")
else:
import math
LCM = 0
if num1>= num2:
test = num1
else:
test = num2
while LCM == 0:
if test%num1 ==0 and test%num2 == 0:
LCM = test
else:
test +=1
print("The least common multiple is: ")
print(LCM)
def dotProduct(list1, list2):
import math
i=0
num1 = 0
num2 = 0
product = 0
if isinstance(list1 or list2, (list)):
if len(list1) != len(list2):
return("it is not possible to take the dot product of your vectors")
else:
while i < len(list1):
num1 = list1[i]
num2 = list2[i]
product += num1*num2
i+=1
else:
return("error, one or more of your entries is not a list")
return product
def crossProduct(list1, list2):
import math
crossProduct = []
num1 = 0
num2 = 0
num3 = 0
if isinstance(list1 or list2, (list)):
if len(list1) != 3 or len(list2) != 3:
return("it is not possible to take the cross product of your vectors")
else:
num1= list1[1]*list2[2]-list1[2]*list2[1]
num2= list1[2]*list2[0]-list1[0]*list2[2]
num3= list1[0]*list2[1]-list1[1]*list2[0]
crossProduct.append(num1)
crossProduct.append(num2)
crossProduct.append(num3)
else:
return("error, one or more of your entries is not a list")
return crossProduct