Discuss / Python / 发错地方了 check_abc 函数多余了，囧~

### 发错地方了 check_abc 函数多余了，囧~

Topic source

#### _潴潴俠_

#1 Created at ... [Delete] [Delete and Lock User]
``````import  math

if b * b - 4 * a * c > 0: # 该方程有2个解
x1 = (-b+math.sqrt(b*b-4*a*c)) / (2*a)
x2 = (-b-math.sqrt(b*b-4*a*c)) / (2*a)
return x1,x2
elif b * b - 4 * a * c == 0: # 只有一个解
x = (-b + math.sqrt(b * b - 4 * a * c)) / (2 * a)
return x
else:
return '此方程无解'

def check_abc(a,b,c):

m =''
m2 = ''
m3 = ''

if not isinstance(a,(int,float)):
m = '\'%s\'不是数字' % a
elif a==0:
return '此方程无意义'

if not isinstance(b,(int,float)):
m2 = '\n\'%s\'不是数字' % b

if not isinstance(c,(int,float)):
m3 = '\n\'%s\'不是数字' % c

if len(m+m2+m3)>0:
return a,b,c,m+m2+m3
else:
return True

def operation_abc(a,b,c):
if isinstance(check_abc(a,b,c),bool):
else:
return '一元二次方程：%sx^2 + %sx + %s = 0,%s'% (check_abc(a,b,c)[0],check_abc(a,b,c)[1],check_abc(a,b,c)[2],check_abc(a,b,c)[3])

a = input('一元二次方程：ax^2 + bx + c = 0,请输入 a :')
while not  a.isdigit():
a = input('请输入数字 a :')

b = input('一元二次方程：ax^2 + bx + c = 0,请输入 b :')
while not  b.isdigit():
b = input('请输入数字 b :')

c = input('一元二次方程：ax^2 + bx + c = 0,请输入 c :')
while not  c.isdigit():
c = input('请输入数字 c :')

print(operation_abc(float(a),float(b),float(c)))
``````

• 1