📜  Python 二次方程式

📅  最后修改于: 2020-10-30 00:45:26             🧑  作者: Mango

求解二次方程的Python程序

二次方程:

二次方程式是由拉丁文“ quadrates”(即正方形)构成的。这是一种特殊类型的方程,其形式为:

在这里,“ x”是未知的,您必须找到它,并且“ a”,“ b”,“ c”指定数字,以使“ a”不等于0。如果a = 0,则该方程式不再变为线性。

在等式中,a,b和c称为系数。

让我们举一个例子来解决二次方程8×2 + 16x + 8 = 0

请参阅以下示例:

# import complex math module
import cmath
a = float(input('Enter a: '))
b = float(input('Enter b: '))
c = float(input('Enter c: '))

# calculate the discriminant
d = (b**2) - (4*a*c)

# find two solutions
sol1 = (-b-cmath.sqrt(d))/(2*a)
sol2 = (-b+cmath.sqrt(d))/(2*a)
print('The solution are {0} and {1}'.format(sol1,sol2)) 

输出: