写一个求解一元二次方程组的Python代码吧
时间: 2023-04-08 13:01:13 浏览: 152
python求解一元二次方程组
好的,以下是求解一元二次方程组的Python代码:
```python
import math
def solve_quadratic_equation(a, b, c):
delta = b ** 2 - 4 * a * c
if delta < 0:
return None
elif delta == 0:
x = -b / (2 * a)
return x
else:
x1 = (-b + math.sqrt(delta)) / (2 * a)
x2 = (-b - math.sqrt(delta)) / (2 * a)
return x1, x2
# 例子
a1, b1, c1 = 1, 2, -3
a2, b2, c2 = 2, -3, 1
x1, x2 = solve_quadratic_equation(a1, b1, c1)
print(f"x1={x1}, x2={x2}")
x1, x2 = solve_quadratic_equation(a2, b2, c2)
print(f"x1={x1}, x2={x2}")
```
希望能帮到你!
阅读全文