import math
def quadratic(a, b, c):
# Check if a, b and c are valid number
if not isinstance(a, (int, float)):
return TypeError('Please enter a valid number for a!')
if not isinstance(b, (int, float)):
return TypeError('Please enter a valid number for b!')
return TypeError('Please enter a valid number for c!')
x1 = (-b + math.sqrt(b*b - 4 * a * c)) / (2 * a)
x2 = (-b - math.sqrt(b*b - 4 * a * c)) / (2 * a)
return print('This unary quadratic equation has two outputs. x1 is %.2f, and x2 is %.2f.' % (x1, x2))
print(quadratic(1, 3, -4))
Sign in to make a reply
Jonathon_C
import math
def quadratic(a, b, c):
# Check if a, b and c are valid number
if not isinstance(a, (int, float)):
return TypeError('Please enter a valid number for a!')
if not isinstance(b, (int, float)):
return TypeError('Please enter a valid number for b!')
if not isinstance(b, (int, float)):
return TypeError('Please enter a valid number for c!')
x1 = (-b + math.sqrt(b*b - 4 * a * c)) / (2 * a)
x2 = (-b - math.sqrt(b*b - 4 * a * c)) / (2 * a)
return print('This unary quadratic equation has two outputs. x1 is %.2f, and x2 is %.2f.' % (x1, x2))
print(quadratic(1, 3, -4))