Python 当elif行为真时,Break函数不起作用 start=input('输入二次方程:') w=start.split() 而len(w)!=7: 开始=输入('正确输入二次方程:') w=start.split() 当x

Python 当elif行为真时,Break函数不起作用 start=input('输入二次方程:') w=start.split() 而len(w)!=7: 开始=输入('正确输入二次方程:') w=start.split() 当x,python,if-statement,while-loop,break,Python,If Statement,While Loop,Break,我试过只做“else”块,但仍然不起作用。我试图做的是检查输入是否实际上是一个二次方程。错误的条件是elif not w[x]。isdigit()和'x'不在w[x]和w[x]中!='-'或“+”或“=”:,它不能满足您的需要 w[x]!='-'或“+”或“=”:部分: 类似于(w[x]!='-')或('+')或('='): 不像w[x]!=(“-”或“+”或“=”): 您想要的是w[x]不在'-+=':与前一个相同 start = input('Enter quadratic equa

我试过只做“else”块,但仍然不起作用。我试图做的是检查输入是否实际上是一个二次方程。

错误的条件是
elif not w[x]。isdigit()和'x'不在w[x]和w[x]中!='-'或“+”或“=”:
,它不能满足您的需要


w[x]!='-'或“+”或“=”:
部分:

  • 类似于
    (w[x]!='-')或('+')或('='):
  • 不像
    w[x]!=(“-”或“+”或“=”):

您想要的是
w[x]不在'-+='
:与前一个相同

start = input('Enter quadratic equation: ')
w = start.split()
while len(w) != 7:
    start = input('Enter quadratic equation correctly: ')
    w = start.split()
while x < len(w):
        if "x" in w[x] and '^2' in w[x]:
            a = w[x]
            if a == "x^2":
                a = 1
            else:
                a = a.replace('x^2', '')
                a = int(a)
            if w[x-1] == '-':
                a = a * (-1)
            else:
                a = a
        elif 'x' in w[x] and '^' not in w[x]:
            b = w[x]
            if b == 'x':
                b = 1
            else:
                b = b.replace('x', '')
                b = int(b)
            if w[x-1] == '-':
                b = b * (-1)
            else:
                b = b
        elif w[x].isdigit() and 'x' not in w[x] and w[x] != '0':
            c = w[x]
        elif w[x] == '-' or '+' or '=':
            s = 0
        elif not w[x].isdigit() and 'x' not in w[x] and w[x] != '-' or '+' or '=':
            print('Mistake')
            break #Would not this code here work?
        x += 1  

你能分享一下你是如何写出你的二次方程的吗?例如:3x^2+12x+13=0谢谢!但在我输入“a”之后,它仍然没有打印“错误”@EgorK刚刚看到它之前的一个错误也是出于同样的原因,看我的edit@EgorK你可以考虑对答案投赞成票,如果你满意的话就接受它(左边绿色的勾号)
    elif w[x] in '-+=':
        s = 0
    elif not w[x].isdigit() and 'x' not in w[x] and w[x] not in '-+=':
        print('Mistake')
        break