OK, so I’ve finally started with math in python, which is (so far) surprisingly not as hard as I thought it would be(I don’t know any calculus, or trigonometry, and only know basic algebra).
I’m trying to create a program from scratch that factors quadratic equations. Here is what I have so far (Sorry if it’s poorly written):
def factor(arg):
o = arg
n = o
x = 2
factors = [o]
while abs(o) >= x:
if (o) % x == 0:
n = o / x
factors.append(n)
x += 1
else:
x += 1
return factors
A = int(raw_input("What is A in your quadratic equation? A = "))
B = int(raw_input("What is B in your quadratic equation? B = "))
C = int(raw_input("What is C in your quadratic equation? C = "))
Br = abs(B) + abs(A) # Range of B
Bpf = range (-Br, Br + 1) # Possible factors of B
ACpf = factor(A * C) # Possible factors of (A * C)
for i in ABpf:
ACpf.append(-i)
cf = [] # Common factors
for i in Bpf:
for j in ACpf:
if i == j:
cf.append(i)
print cf
I ran this script through the terminal, it asked me what A B and C are, then it froze up for about thirty seconds. After it unfroze below what I typed it said ‘killed’.
Does anyone know what caused this? I appreciate any answers or advice.
Modify your code a bit like this:
Now try running it. You should get a result.