Advertisement
khaiwen1111

Untitled

Oct 24th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Fri Oct 25 10:46:24 2019
  4.  
  5. @author: Seow Khaiwen
  6. """
  7.  
  8. import math
  9. import cmath
  10. a = input("input the value of coefficient a: ")
  11. b = input("input the value of coefficient b: ")
  12. c = input("input the value of coefficient c: ")
  13. a=float(a)
  14. b=float(b)
  15. c=float(c)
  16. discri= b**2-4*a*c
  17. print("the discriminate is: ","%.6f"%discri)
  18. if discri > 0:
  19.     x1=(-b+math.sqrt(discri))/2*a
  20.     x2=(-b-math.sqrt(discri))/2*a
  21.     print("the equation has two distinct real roots" )
  22.     print("x1 = ","%.6f"%round(x1,6))
  23.     print("x2 = ","%.6f"%round(x2,6))
  24. elif discri < 0:
  25.     x1=(-b+cmath.sqrt(discri))/2*a
  26.     x2=(-b-cmath.sqrt(discri))/2*a
  27.     print("the equation has two complex roots")
  28.     print("x1 = ", "%.6f"%x1.real,"+","%.6f"%x1.imag,"i")
  29.     print("x2 = ","%.6f"%x2.real,"%.6f"%x2.imag,"i")
  30. else:
  31.     x1=-b/2*a
  32.     print("the equation has one repeated root")
  33.     print("x1 = x2 = ","%.6f"%x1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement