
#  Program solves quadratic equation:
#  Inputs: a, b, c for
#        ax**2  + bx + c = 0  
#  Outputs: Two real roots     
#
import sys
import numpy as np
import matplotlib.pyplot as plt
#   Input coefficients a, b, c   
#   
###########################################################
#   YOUR CODE GOES HERE
#        Allow user to enter coefficients a, b, c
#        Check for real roots
#        if roots not real, print message and sys.exit(0)
############################################################

#  Print results 
print (' For quadratic equation : ')
print (' %f * x**2 + %f *x  + %f  = 0' % (a,b,c)) 
# If real roots found
print (' Real roots are: %f  and %f '  % (root1, root2)) 
########################################################
# YOUR CODE GOES HERE:
#  Create 'lambda' function f to model actual equation:
#       a*x^2 + b*x  + c 
#  Look up 'python lambda" on-line if you don't know format 
#
########################################################
#
#  Plot quadratic equation
#
xlim1 = min(root1,root2) -5
xlim2 = max(root1,root2) +5 
xvalues = np.linspace(xlim1,xlim2,500)
yvalues = np.array([ f(x)  for x in xvalues])
plt.plot(xvalues, yvalues, 'b-')
plt.axhline(0, color='black', lw=1)  #  line on x-axis
plt.axvline(0, color='black', lw=1)  #  line on y axis
plt.grid(True)                       #  Adds grid lines
plt.title('Plot of quadratic equation')
plt.show()
# Additional challenge:
#   Add logic to deal with imaginary (non-real) roots.
   

