Advertisement
HowLig

Phương Trình Bậc Hai

Feb 24th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. import math
  2. print("ax^2+bx+c=0")
  3. a=int(input("Nhập a:"))
  4. b=int(input("Nhập b:"))
  5. c=int(input("Nhập c:"))
  6. D=b*b-4*a*c
  7. if D<0:
  8.     print("Phương Trình Vô nghiệm")
  9. elif D==0:
  10.     x1=x2=(-b/2*a)
  11.     print("X1=X2={0}".format(x1))
  12. elif D>0:
  13.     x1=(-b+math.sqrt(D))/2*a
  14.     x2=(-b-math.sqrt(D))/2*a
  15.     print("X1={0} , X2={1}".format(x1,x2))
  16. elif a+b+c==0:
  17.     x1=1
  18.     x2=c/a
  19.     print("X1=1, X2={0}".format(X2))
  20. elif a-b+c==0:
  21.     x1=-1
  22.     x2=-c/a
  23.     print("X1=-1  , X2={0}".format(x1))
  24. else:
  25.     print("Sai cú pháp")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement