Apr-20-2023, 07:33 PM
(This post was last modified: Apr-20-2023, 07:47 PM by deanhystad.)
I reworked some of the problems by making A,B,C int but am now running into math domain errors
code
code
import math equation = [] operation_chosen = input("type of quadratic") if operation_chosen == "standard form": e = input("enter equation") for i in e: equation.append(i) numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'] operations = ['+', '-'] a = [] b = [] c = [] print(equation) operation = [] x = 0 while 'x' in equation: if equation[equation.index('x') + 1] == '^': del equation[equation.index('x') + 2] del equation[equation.index('x') + 1] del equation[equation.index('x')] else: del equation[equation.index('x')] print(equation) while x < len(equation): if equation[x] in operations: operation.append(x) x += 1 print(operation) for i in range(operation[0]): a += equation[i] for i in range(operation[0], operation[1]): b += equation[i] for i in range(operation[1], len(equation)): c += equation[i] while '+' in b: del b[b.index('+')] while '-' in b: del b[b.index('-')] while '+' in c: del c[c.index('+')] while '-' in c: del c[c.index('-')] A = ''.join(a) B = ''.join(b) C = ''.join(c) a2 = int(A) b2 = int(B) b3 = math.pow(b2, 2) c2 = int(C) print(a) print(b) print(c) print(A) print(B) print(C) print(a2) print(b2) print(b3) print(c2) anser = (-b2 + math.sqrt(b3-4*a2*c2)/2*a2) print(a) print(b) print(c) print(A) print(B) print(C)
(Apr-20-2023, 06:55 PM)deanhystad Wrote: I don't think this parsing code works quite right either.
for i in e: equation.append(i) numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'] operations = ['+', '-'] a = [] b = [] c = [] print(equation) operation = [] x = 0 while 'x' in equation: if equation[equation.index('x') + 1] == '^': del equation[equation.index('x') + 2] del equation[equation.index('x') + 1] del equation[equation.index('x')] else: del equation[equation.index('x')] print(equation) while x < len(equation): if equation[x] in operations: operation.append(x) x += 1 print(operation) for i in range(operation[0]): a += equation[i] for i in range(operation[0], operation[1]): b += equation[i] for i in range(operation[1], len(equation)): c += equation[i] while '+' in b: del b[b.index('+')] while '-' in b: del b[b.index('-')] while '+' in c: del c[c.index('+')] while '-' in c: del c[c.index('-')]I don't see where "-" has any affect on the results. x^2 - x -10 is evaluated the same as x^2 + x + 10
You should rethink your approach.
deanhystad write Apr-20-2023, 07:47 PM:
Please wrap code in python tags to retain proper indenting.
Use the New Reply button instead of the Reply button unless referencing something in another post. Your post should not contain other posts, just portions of other posts that are needed to understand your new post.
Please wrap code in python tags to retain proper indenting.
Use the New Reply button instead of the Reply button unless referencing something in another post. Your post should not contain other posts, just portions of other posts that are needed to understand your new post.