In [14]:
import math
In [15]:
def main():
    x = int(input("Enter a number: "))
    if x >= 0:
       result = math.sqrt(x)
       print(result)
In [16]:
main()
Enter a number: -1
In [17]:
def main():
    x = int(input("Enter a number: "))
    try:
       result = math.sqrt(x)
       print(result)
    except ValueError:
        print("The sqrt of a negative number was attempted!")
In [18]:
main()
Enter a number: 10
3.1622776601683795
In [19]:
main()
Enter a number: -3
The sqrt of a negative number was attempted!
In [27]:
def main():
    print("This finds the roots of a qudaratic")
    try:
        a,b,c = eval(input("Please enter the coefficients (a,b,c): "))
        disc_root = math.sqrt(b**2 - 4 * a * c)
        root1 = (-b + disc_root)/(2*a)
        root2 = (-b - disc_root)/(2*a)
        print("The solutions are:", root1, root2)
    except ValueError:
        print("There are no real solutions!")
    except NameError:
        print("Bad data entered!")
In [28]:
main()
This finds the roots of a qudaratic
Please enter the coefficients (a,b,c): foobar
Bad data entered!