The document describes an experiment to write a Python program that finds the roots of a quadratic equation. The program takes coefficients a, b, and c as input from the user, calculates the discriminant d, and determines if the roots are real/imaginary or equal/distinct based on the sign of d. It then prints the appropriate output including the calculated real or complex roots.
Original Description:
To write a program to find the roots of a quadratic equation.
The document describes an experiment to write a Python program that finds the roots of a quadratic equation. The program takes coefficients a, b, and c as input from the user, calculates the discriminant d, and determines if the roots are real/imaginary or equal/distinct based on the sign of d. It then prints the appropriate output including the calculated real or complex roots.
The document describes an experiment to write a Python program that finds the roots of a quadratic equation. The program takes coefficients a, b, and c as input from the user, calculates the discriminant d, and determines if the roots are real/imaginary or equal/distinct based on the sign of d. It then prints the appropriate output including the calculated real or complex roots.
13.07.2023 AIM: To write a program to find the roots of a quadratic equation.
CODE:
import cmath print('The roots are imaginary.')
a=eval(input('Enter coefficient of x square: sq=cmath.sqrt(d) ')) x1=(-b+sq)/(2*a) b=eval(input('Enter coefficient of x:')) if x1.imag==0: c=eval(input('Enter constant term:')) x1=x1.real d=(b**2)-(4*a*c) x2=(-b-sq)/(2*a) if d==0: if x2.imag==0: print('The roots are real and equal.') x2=x2.real elif d>0: print('Roots of equation are',x1,'and',x2,'.') print('The roots are real and distinct.') elif d<0: