Exception Handling

In [39]:
import math

def quad6():

        a, b, c = eval(input("\nPlease enter the coefficients (a, b, c): "))
        discrim = b**2 - 4 * a * c
        disc_root = math.sqrt(discrim)
        root1 = (-b + disc_root) / (2 * a)
        root2 = (-b - disc_root) / (2 * a)    
        print("\nThe solutions are: ", root1, root2)
    except ValueError as exp:
        if str(exp) == "math domain error":
            print("\nNo real roots!")
        elif str(exp) == "too many values to unpack (expected 3)":
            print("Too many numbers!")
            print("Not sure what happened, but it happened!")
    except (SyntaxError, NameError):
        print("\nBad input!")
    except TypeError:
In [37]:
Please enter the coefficients (a, b, c): 1,2
Not sure what happened, but it happened!
In [38]:
a,b,c = 1,2
ValueError                                Traceback (most recent call last)
<ipython-input-38-eeebabcfeff0> in <module>()
----> 1 a,b,c = 1,2

ValueError: not enough values to unpack (expected 3, got 2)
In [40]:
import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
In [ ]:
    print("Hello World")