Skip to content

Commit

Permalink
[scripts/pycalc] solve quadratic numbers with complex roots
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitmel committed Jan 22, 2024
1 parent 9e0172c commit a5c8958
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions script-resources/pycalc_startup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from math import *
import cmath
import math
from fractions import Fraction
from math import *
from typing import Set


Expand All @@ -13,20 +15,11 @@ def factors(n: int) -> Set[int]:


def solve_quadratic(a: float, b: float, c: float) -> None:
if a == 0:
raise Exception("not a quadratic equation")
else:
d = b ** 2 - 4 * a * c
print("D = " + str(d))
if d < 0:
print("no solutions")
elif d > 0:
sd = sqrt(d)
print("sqrt(D) = " + str(sd))
print("x1 = " + str((-b + sd) / (2 * a)))
print("x2 = " + str((-b - sd) / (2 * a)))
else:
print("x = " + str(-b / (2 * a)))
d = b ** 2 - 4 * a * c
sd = cmath.sqrt(d)
print("sqrt(D) = " + str(sd))
print("x1 = " + str((-b + sd) / (2 * a)))
print("x2 = " + str((-b - sd) / (2 * a)))


def cot(x: float) -> float:
Expand Down

0 comments on commit a5c8958

Please sign in to comment.