Discuss / Python / 老年人学python

老年人学python

Topic source

import math

defquadratic(a,b,c):

ifnotisinstance(a or b or c,(int,float)):

raiseTypeError('bad operand type')

elif b*b<4*a*c:

print('无解')

else:

        x1 =(-b + math.sqrt(b**2-4*a*c))/2/a

        x2 =(-b - math.sqrt(b**2-4*a*c))/2/a

return x1,x2

x=quadratic(1,8,1)

print(x)

elimy君

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

您好,我参照你写的,运行不出结果呢,可以帮忙看看哪里的问题么

import math

def quadratic(a,b,c):

    if not isinstance(a or b or c,(int,float)):

        raise TypeError('bad operand type')

    elif b**2<4*a*c:

         print('无解')

    else:

        x1=(-b+math.sqrt(b**2-4*a*c))/(2*a)

        x2=(-b-math.sqrt(b**2-4*a*c))/(2*a)

        return x1,x2

lov1394_198

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

有结果啊,只是你没打印结果,加一句print(quadratic(1,8,1))


  • 1

Reply