Home > Backend Development > Python Tutorial > Use Python to write a function that finds the solution to a quadratic equation in real numbers

Use Python to write a function that finds the solution to a quadratic equation in real numbers

高洛峰
Release: 2017-03-27 15:09:32
Original
2168 people have browsed it

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!'
Copy after login

使用Python写一个求实数内二次方程解的函数

使用Python写一个求实数内二次方程解的函数

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template