Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
code problems
#5
I reworked some of the problems by making A,B,C int but am now running into math domain errors
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.
Reply


Messages In This Thread
code problems - by bbm007 - Apr-19-2023, 08:27 PM
RE: code problems - by deanhystad - Apr-19-2023, 11:22 PM
RE: code problems - by bbm007 - Apr-20-2023, 06:35 PM
RE: code problems - by deanhystad - Apr-20-2023, 06:55 PM
RE: code problems - by bbm007 - Apr-20-2023, 07:33 PM
RE: code problems - by deanhystad - Apr-20-2023, 08:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  multiple problems with code SrijaRamarthy 2 1,943 Nov-06-2019, 06:24 AM
Last Post: SrijaRamarthy
  code problems lokchi2017 3 2,807 Jul-06-2018, 01:58 AM
Last Post: Zombie_Programming
  code editor/ IDE problems nameno1had 2 3,420 Mar-12-2018, 10:09 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020