fork download
  1. #公式
  2. #x1 = (-b+math.sqrt(b*b-4*a*c)/2*a)
  3. #x2 = (-b-math.sqrt(b*b-4*a*c)/2*a)
  4. import math
  5. def quadratic(a, b, c):
  6. s = 'yes'
  7. if (b*b)-(4*b*c) > 0:
  8. print(s)
  9.  
  10. def quadratic(a, b, c):
  11. x1 = ((-b+math.sqrt(b*b-4*a*c))/(2*a))
  12. x2 = ((-b-math.sqrt(b*b-4*a*c))/(2*a))
  13. return x1, x2
  14. # 测试:
  15. print('quadratic(2, 3, 1) =', quadratic(2, 3, 1))
  16. print('quadratic(1, 3, -4) =', quadratic(1, 3, -4))
  17.  
  18. if quadratic(2, 3, 1) != (-0.5, -1.0):
  19. print('测试失败')
  20. elif quadratic(1, 3, -4) != (1.0, -4.0):
  21. print('测试失败')
  22. else:
  23. print('测试成功')
Runtime error #stdin #stdout #stderr 0.11s 23516KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 7, in <module>
NameError: name 'b' is not defined