0

我是 python 新手,这非常令人困惑。如何在此处使用 sys.float_info.epilson 将浮点数与 0 进行比较?

 #!/usr/bin python 3

 import cmath
 import math
 import sys

 print ("ax^2 + bx + c = 0")

 while True:

         try:
                 a = float(input("Enter a: "))
                 b = float(input("Enter b: "))
                 c = float(input("Enter c: "))
         except ValueError:
                 print("Please enter a number!")
         else:
                 print (a,"x^2 + ",b,"x + ",c," = 0")
                 x = (b**2) - (4*a*c)

                 x1 = (-b+cmath.sqrt(x))/(2*a)
                 x2 = (-b-cmath.sqrt(x))/(2*a)

                 print ("x1= ",x1)
                 print ("x2= ",x2)

 exit(0)
4

0 回答 0