Advertisement
1nikitas

Untitled

Apr 6th, 2022
997
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. def solve(*coefficients):
  2.     if len(coefficients) == 3:
  3.         d = coefficients[1] ** 2 - 4 * coefficients[0] * coefficients[2]
  4.         if coefficients[0] == 0 and coefficients[1] == 0 and coefficients[2] == 0:
  5.             x = ["all"]
  6.         elif coefficients[0] == 0 and coefficients[1] == 0:
  7.             x = ''
  8.         elif coefficients[0] == 0:
  9.             x = [-coefficients[2] / coefficients[1]]
  10.         elif coefficients[1] == 0:
  11.             x = [(coefficients[2] / coefficients[0]) ** 0.5]
  12.         elif coefficients[2] == 0:
  13.             x = [0, -coefficients[1] / coefficients[0]]
  14.         else:
  15.             if d == 0:
  16.                 x = [-coefficients[1] / (2 * coefficients[0])]
  17.             elif d < 0:
  18.                 x = ''
  19.             else:
  20.                 x = [float((-coefficients[1] + d ** 0.5) / (2 * coefficients[0])),
  21.                      float((-coefficients[1] - d ** 0.5) / (2 * coefficients[0]))]
  22.         return x
  23.     elif len(coefficients) == 2:
  24.         return [-coefficients[1] / coefficients[0]]
  25.     elif len(coefficients) == 1:
  26.         if coefficients[0] == 0:
  27.             return ["all"]
  28.         else:
  29.             return []
  30.     else:
  31.         return ["all"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement