Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Fri Oct 25 10:46:24 2019
- @author: Seow Khaiwen
- """
- import math
- import cmath
- a = input("input the value of coefficient a: ")
- b = input("input the value of coefficient b: ")
- c = input("input the value of coefficient c: ")
- a=float(a)
- b=float(b)
- c=float(c)
- discri= b**2-4*a*c
- print("the discriminate is: ","%.6f"%discri)
- if discri > 0:
- x1=(-b+math.sqrt(discri))/2*a
- x2=(-b-math.sqrt(discri))/2*a
- print("the equation has two distinct real roots" )
- print("x1 = ","%.6f"%round(x1,6))
- print("x2 = ","%.6f"%round(x2,6))
- elif discri < 0:
- x1=(-b+cmath.sqrt(discri))/2*a
- x2=(-b-cmath.sqrt(discri))/2*a
- print("the equation has two complex roots")
- print("x1 = ", "%.6f"%x1.real,"+","%.6f"%x1.imag,"i")
- print("x2 = ","%.6f"%x2.real,"%.6f"%x2.imag,"i")
- else:
- x1=-b/2*a
- print("the equation has one repeated root")
- print("x1 = x2 = ","%.6f"%x1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement