-1
import math
a,b,c = map(int,input().split())
x = float((-b + math.sqrt(b**2-4*a*c))/2*a)
y = float((-b - math.sqrt(b**2-4*a*c))/2*a)

if y>x:
    x = x1
    y = x
    x1 = y
    
if (b**2-4*a*c >=1):
    print("Two different roots "+"x1=",int(x)," , "+"x2=",int(y),sep="")
elif (b**2-4*a*c == 0):
    print("Two same roots x=",int(x),sep="")
else:
    print("No real root")

Error message:

Traceback (most recent call last):
  File "/7760537/code_7760537.py", line 3, in 
    x = float((-b + math.sqrt(b**2-4*a*c))/2*a)
ValueError: math domain error

What's wrong in code?? OAO What is "math domain error" meaning?? Sorry my English is not good....

DYZ
  • 55,249
  • 10
  • 64
  • 93
  • What do you think is the value of `sqrt(b**2-4*a*c)` of `b**2-4*a*c` is negative? – DYZ Jun 25 '21 at 06:39

1 Answers1

0

Maybe your b**2-4*a*c gives a negativ number which doesn't work in math, you should put a

delta = b**2-4*a*c
if delta > 0:
    x = float((-b + math.sqrt(delta))/2*a)
    y = float((-b - math.sqrt(delta))/2*a)

Sozy
  • 177
  • 9