python 上的二次公式需要帮助

Need Help for Quadratic formula on python

我刚开始在学校学习 Python,这是我的二次方程求解器代码。问题出在第 4 行。

a=int(input('a= ')) # A-stvis mnishvnelobis micema
b=int(input('b= ')) # B-stvis mnishvnelobis micema
c=int(input('c= ')) # C-stvis mnishvenlobis micema
int(a)*(x2)+int(b)*x+c=0
d=(-b2)-4*a*c
x1=-b+(d**(1/2))
x2=-b-(d**(1/2))
from math import sqrt

a = int(input('a= ')) # A-stvis mnishvnelobis micema
b = int(input('b= ')) # B-stvis mnishvnelobis micema
c = int(input('c= ')) # C-stvis mnishvenlobis micema
d = b**2 - 4*a*c
x1 = (-b - sqrt(d))/2
x2 = (-b + sqrt(d))/2

print("x1 =", x1)
print("x2 =", x2)

不需要你的方程式,python不明白。喜欢的可以评论哦

尝试使用平方根 (sqrt) 而不是求幂 (**)

import math as m

print('QUADRATIC EQUATION FORM - (a)x^2 + (b)x + (c) = 0')
a = float(input('Enter the value of a '))
b = float(input('Enter the value of b '))
c = float(input('Enter the value of c '))

check = b**2 - 4*a*c

##### FOR NO DEFINITE ROOTS #####
if check < 0 :
  print("No real root")

##### FOR TWO DISTINCT ROOTS #####

if check > 0 :
  print("Two Distinct roots - ")
  root_1 = -b + m.sqrt(b**2 - 4*a*c)
  root_2 = -b - m.sqrt(b**2 - 4*a*c)
  print('Root 1 = ',root_1)
  print('Root 2 = ',root_2)

##### FOR EQUAL ROOTS #####

if check == 0 :
  print("Two Equal roots - ")
  root_1 = -b + m.sqrt(b**2 - 4*a*c)
  root_2 = root_1
  print('Root 1 = ',root_1)
  print('Root 2 = ',root_2)