当 elif 行为真时,中断功能不起作用
Break function does not work when the elif line is true
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
我试过只做 'else' 块,但仍然行不通。我想做的是检查输入是否实际上是二次方程。
错误的条件是 elif not w[x].isdigit() and 'x' not in w[x] and w[x] != '-' or '+' or '=':
,它不符合您的要求 want/need
w[x] != '-' or '+' or '=':
部分:
- 就像
(w[x]!='-') or ('+') or ('='):
- 不喜欢
w[x] != ('-' or '+' or '='):
你要的是w[x] not in '-+='
:和上一个一样
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
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
我试过只做 'else' 块,但仍然行不通。我想做的是检查输入是否实际上是二次方程。
错误的条件是 elif not w[x].isdigit() and 'x' not in w[x] and w[x] != '-' or '+' or '=':
,它不符合您的要求 want/need
w[x] != '-' or '+' or '=':
部分:
- 就像
(w[x]!='-') or ('+') or ('='):
- 不喜欢
w[x] != ('-' or '+' or '='):
你要的是w[x] not in '-+='
:和上一个一样
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