Home > Article > Backend Development > Use Python to write a function that finds the solution to a quadratic equation in real numbers
def quar(a,b,c):
if not isinstance(a,(int,float))|isinstance(b,(int,float))|isinstance(c,(int,float)):
raise TypeError('Wrong Type inputing!')
else:
from math import sqrt
tmp1=b**2-4*a*c
if tmp1>0:
return '%.04f'%float((-b+sqrt(tmp1))/(2*a)),'%.04f'%((-b-sqrt(tmp1))/(2*a))
elif tmp1==0:
return -b/(2*a)
else:
return 'No rational answer!'


Listen
The above is the detailed content of Use Python to write a function that finds the solution to a quadratic equation in real numbers. For more information, please follow other related articles on the PHP Chinese website!