#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ ENGG1811 Lecture Week 4 Handling two error cases in solving a quadratic equation - Negative discriminant - Divide by 0 """ # Import the math module - Need that for square root import math # Specify the coefficients of the quadratic equation print("Please input three numbers separated by commas") a, b, c = eval(input("Numbers please: ")) # Compute the discriminant discriminant = b**2-4*a*c if a == 0: print('The leading coefficient cannot be zero!') else: if discriminant < 0: print('Sorry, this program cannot handle complex roots!') else: # Compute the square root of the discriminant root_discriminant = math.sqrt(discriminant) root1 = (-b + root_discriminant)/(2*a) root2 = (-b - root_discriminant)/(2*a) # Display the answers print('The roots are ',root1,' and ', root2)