import math
def quadratic(a, b, c):
if not isinstance(a+b+c, (int, float)):
raise TypeError('bad operand type')
if b**2-4*a*c >= 0:
x1 = (-b-math.sqrt(b**2-4*a*c))/(2*a)
x2 = (-b+math.sqrt(b**2-4*a*c))/(2*a)
print(x1, x2)
else:
print("don't have real root")
a = float(input('enter a:'))
b = float(input('enter b:'))
c = float(input('enter c:'))
quadratic(a, b, c)
Sign in to make a reply
友仔
import math
def quadratic(a, b, c):
if not isinstance(a+b+c, (int, float)):
raise TypeError('bad operand type')
if b**2-4*a*c >= 0:
x1 = (-b-math.sqrt(b**2-4*a*c))/(2*a)
x2 = (-b+math.sqrt(b**2-4*a*c))/(2*a)
print(x1, x2)
else:
print("don't have real root")
a = float(input('enter a:'))
b = float(input('enter b:'))
c = float(input('enter c:'))
quadratic(a, b, c)