Write Pythonic code to solve the quadratic equation ax**2 + bx + c = 0 by getting input for coefficients from the user.

'''  The solutions of the quadratic equation ax2 + bx + c = 0 correspond to the roots of the function f(x) = ax2 + bx + c, since they are the values of x for which f(x) = 0.  ''' 

''' note: Enter valid numbers '''

import math  ''' import library '''

a=int(input('Enter value of a: '))  // Accept values from user

b=int(input('Enter value of b: '))

c=int(input('Enter value of c: '))

print('quadratic equation is: ',a,'x**2 + ',b,'x + ',c,sep='') 

''' calculate result '''

d = (b**2) - (4*a*c)

s1 = (-b-math.sqrt(d))/(2*a)

s2 = (-b+math.sqrt(d))/(2*a)

''' printing result '''

print('first value is: ',s1) 

print('second value is: ',s2)

0 Comments