print("\nthe solutions are:"root root main( exception handling our quadratic program uses decision structures to avoid taking the square root of negative number and generating an error at run-time this is common pattern in many programsusing decisions to protect against rare but possible errors in the case of the quadratic solverwe checked the data before the call to the sqrt function sometimes functions themselves check for possible errors and return special value to indicate that the operation was unsuccessful for examplea different square root operation might return negative number (say- to indicate an error since the square root function should always return the non-negative rootthis value could be used to signal that an error has occurred the program would check the result of the operation with decision discrt othersqrt( * * *cif discrt print "no real roots elsesometimes programs become so peppered with decisions to check for special cases that the main algorithm for handling the run-of-the-mill cases seems completely lost programming language designers have come up with mechanisms for exception handling that help to solve this design problem the idea of an exception handling mechanism is that the programmer can write code that catches and deals with errors that arise when the program is running rather than explicitly checking that each step in the algorithm was successfula program with exception handling can in essence say"do these stepsand if any problem crops uphandle it this way we're not going to discuss all the details of the python exception handling mechanism herebut do want to give you concrete example so you can see how exception handling works and understand programs that use it in pythonexception handling is done with special control structure that is similar to decision let' start with specific example and then take look at the general approach here is version of the quadratic program that uses python' exception mechanism to catch potential errors in the math sqrt functionquadratic py import math def main()print "this program finds the real solutions to quadratic\ntry