Discuss / Python / 前方改进---参考了别人的.

前方改进---参考了别人的.

Topic source

longtometosee

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

import math

def my_math(a,b,c):

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

        raise TypeError ('bad operand type')

    if a==0:

        return "非一元二次方程"

    else:

        dist=pow(b,2)-4*a*c  

        if dist==0:

            result=(-b)/(2*a)

            print('x1,x2=',result)

        elif dist<0:

            print('无实数解')

        else:

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

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

            print('x1=',x1)

            print('x2=',x2)

print(my_math(1,5,7))

print(my_math(3,8,3))

print(my_math(0,7,8))


  • 1

Reply