Discuss / Python / 求大神指导为啥TypeError那块错了

求大神指导为啥TypeError那块错了

Topic source

Thriller

#1 Created at ... [Delete] [Delete and Lock User]

import math

def quadratic(a,b,c):

    for i in(a,b,c):

        if not isinstance(i,(int,float)):

                raise TypeError('bad operand type')

    a=float(a)

    b=float(b)

    c=float(c)

    deierta=math.sqrt(b*b-4*a*c)

    if a==0 and b==0 and c==0:

        print('方程有无穷多解')

    elif a==0 and b==0 and c!=0:

        print('方程无解')

    elif a==0 and b!=0:

        print('方程的解为%s,%s' %(-c/b,-c/b))

    else:

        if b*b-4*a*c<0:

            print('方程无解')

        else:

            x1=(-b+deierta)/(2*a)

            x2=(-b-deierta)/(2*a)

            print('方程的解为%s,%s' %(x1,x2))

            return x1,x2

m=1

while m==1:

    print('求解一元二次方程')      

    a=input('请输入第一个参数a\n')

    b=input('请输入第二个参数b\n')

    c=input('请输入第三个参数c\n')

    quadratic(a,b,c)

    print('have finished the work')

Thriller

#2 Created at ... [Delete] [Delete and Lock User]

已经找到错误了。


  • 1

Reply